#[repr(transparent)]pub struct Alignment(_);
ptr_alignment_type
#102070)Expand description
A type storing a usize
which is a power of two, and thus
represents a possible alignment in the rust abstract machine.
Note that particularly large alignments, while representable in this type, are likely not to be supported by actual allocators and linkers.
Implementations
sourceimpl Alignment
impl Alignment
sourcepub const fn of<T>() -> Self
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub const fn of<T>() -> Self
ptr_alignment_type
#102070)Returns the alignment for a type.
This provides the same numerical value as mem::align_of
,
but in an Alignment
instead of a `usize.
sourcepub const fn new(align: usize) -> Option<Self>
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub const fn new(align: usize) -> Option<Self>
ptr_alignment_type
#102070)Creates an Alignment
from a usize
, or returns None
if it’s
not a power of two.
Note that 0
is not a power of two, nor a valid alignment.
const: unstable · sourcepub unsafe fn new_unchecked(align: usize) -> Self
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub unsafe fn new_unchecked(align: usize) -> Self
ptr_alignment_type
#102070)Creates an Alignment
from a power-of-two usize
.
Safety
align
must be a power of two.
Equivalently, it must be 1 << exp
for some exp
in 0..usize::BITS
.
It must not be zero.
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)Returns the alignment as a NonZeroUsize
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)Returns the alignment as a usize
Trait Implementations
sourceimpl From<Alignment> for NonZeroUsize
impl From<Alignment> for NonZeroUsize
sourcefn from(align: Alignment) -> NonZeroUsize
fn from(align: Alignment) -> NonZeroUsize
sourceimpl Ord for Alignment
impl Ord for Alignment
1.21.0 · sourceconst fn max(self, other: Self) -> Selfwhere
Self: Sized,
const fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourceconst fn min(self, other: Self) -> Selfwhere
Self: Sized,
const fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized,
Self: PartialOrd,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized,
Self: PartialOrd,
sourceimpl PartialOrd<Alignment> for Alignment
impl PartialOrd<Alignment> for Alignment
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more