pub struct Alignment(_);ptr_alignment_type)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 MIN: Alignment = Self(AlignmentEnum::_Align1Shl0)
🔬This is a nightly-only experimental API. (ptr_alignment_type)
pub const MIN: Alignment = Self(AlignmentEnum::_Align1Shl0)
ptr_alignment_type)The smallest possible alignment, 1.
All addresses are always aligned at least this much.
Examples
#![feature(ptr_alignment_type)]
use std::ptr::Alignment;
assert_eq!(Alignment::MIN.as_usize(), 1);sourcepub const fn of<T>() -> Alignment
🔬This is a nightly-only experimental API. (ptr_alignment_type)
pub const fn of<T>() -> Alignment
ptr_alignment_type)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<Alignment>
🔬This is a nightly-only experimental API. (ptr_alignment_type)
pub const fn new(align: usize) -> Option<Alignment>
ptr_alignment_type)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) -> Alignment
🔬This is a nightly-only experimental API. (ptr_alignment_type)
pub unsafe fn new_unchecked(align: usize) -> Alignment
ptr_alignment_type)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)
pub fn as_usize(self) -> usize
ptr_alignment_type)Returns the alignment as a usize
sourcepub const fn as_nonzero(self) -> NonZeroUsize
🔬This is a nightly-only experimental API. (ptr_alignment_type)
pub const fn as_nonzero(self) -> NonZeroUsize
ptr_alignment_type)Returns the alignment as a NonZeroUsize
sourcepub fn log2(self) -> u32
🔬This is a nightly-only experimental API. (ptr_alignment_type)
pub fn log2(self) -> u32
ptr_alignment_type)Returns the base-2 logarithm of the alignment.
This is always exact, as self represents a power of two.
Examples
#![feature(ptr_alignment_type)]
use std::ptr::Alignment;
assert_eq!(Alignment::of::<u8>().log2(), 0);
assert_eq!(Alignment::new(1024).unwrap().log2(), 10);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 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<Alignment> for Alignment
impl PartialOrd<Alignment> for Alignment
sourcefn partial_cmp(&self, other: &Alignment) -> Option<Ordering>
fn partial_cmp(&self, other: &Alignment) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresourceimpl TryFrom<NonZeroUsize> for Alignment
impl TryFrom<NonZeroUsize> for Alignment
type Error = TryFromIntError
type Error = TryFromIntError
sourcefn 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
sourceimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
sourcefn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.