#[repr(transparent)]pub struct Alignment(_);
🔬This is a nightly-only experimental API. (
ptr_alignment_type
#102070)Expand description
一种存储 usize
的类型,它是 2 的幂,因此表示 rust 抽象机中可能的对齐方式。
请注意,虽然在这种类型中可以表示特别大的对齐,但实际分配器和链接器可能不支持。
Implementations§
source§impl Alignment
impl Alignment
sourcepub const MIN: Alignment = Self(AlignmentEnum::_Align1Shl0)
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub const MIN: Alignment = Self(AlignmentEnum::_Align1Shl0)
ptr_alignment_type
#102070)sourcepub const fn of<T>() -> Alignment
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub const fn of<T>() -> Alignment
ptr_alignment_type
#102070)返回类型的对齐方式。
这提供与 mem::align_of
相同的数值,但在 Alignment
而不是 usize
中。
sourcepub const fn new(align: usize) -> Option<Alignment>
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub const fn new(align: usize) -> Option<Alignment>
ptr_alignment_type
#102070)从 usize
创建 Alignment
,如果不是 2 的幂,则返回 None
。
请注意,0
不是 2 的幂,也不是有效的对齐方式。
const: unstable · sourcepub unsafe fn new_unchecked(align: usize) -> Alignment
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub unsafe fn new_unchecked(align: usize) -> Alignment
ptr_alignment_type
#102070)从 usize
的二次幂创建 Alignment
。
Safety
align
必须是 2 的幂。
等效地,对于 0..usize::BITS
中的某些 exp
,它必须是 1 << exp
。
它必须不为零。
const: unstable · sourcepub fn as_usize(self) -> usize
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub fn as_usize(self) -> usize
ptr_alignment_type
#102070)将对齐方式返回为 usize
sourcepub const fn as_nonzero(self) -> NonZeroUsize
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub const fn as_nonzero(self) -> NonZeroUsize
ptr_alignment_type
#102070)将对齐方式返回为 NonZeroUsize
Trait Implementations§
source§impl From<Alignment> for NonZeroUsize
impl From<Alignment> for NonZeroUsize
source§fn from(align: Alignment) -> NonZeroUsize
fn from(align: Alignment) -> NonZeroUsize
从输入类型转换为此类型。
const: unstable · source§impl Ord for Alignment
impl Ord for Alignment
const: unstable · source§impl PartialOrd<Alignment> for Alignment
impl PartialOrd<Alignment> for Alignment
source§impl TryFrom<NonZeroUsize> for Alignment
impl TryFrom<NonZeroUsize> for Alignment
§type Error = TryFromIntError
type Error = TryFromIntError
发生转换错误时返回的类型。
source§fn try_from(
align: NonZeroUsize
) -> Result<Alignment, <Alignment as TryFrom<NonZeroUsize>>::Error>
fn try_from( align: NonZeroUsize ) -> Result<Alignment, <Alignment as TryFrom<NonZeroUsize>>::Error>
执行转换。
impl Copy for Alignment
impl Eq for Alignment
impl StructuralEq for Alignment
impl StructuralPartialEq for Alignment
Auto Trait Implementations§
impl RefUnwindSafe for Alignment
impl Send for Alignment
impl Sync for Alignment
impl Unpin for Alignment
impl UnwindSafe for Alignment
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
从拥有的值中借用。 Read more