Alignment

Struct Alignment 

Source
pub struct Alignment(/* private fields */);
🔬This is a nightly-only experimental API. (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§

Source§

impl Alignment

Source

pub const fn new(align: usize) -> Option<Self>

🔬This is a nightly-only experimental API. (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.

Source

pub const unsafe fn new_unchecked(align: usize) -> Self

🔬This is a nightly-only experimental API. (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.

Source

pub const fn as_usize(self) -> usize

🔬This is a nightly-only experimental API. (ptr_alignment_type #102070)

Returns the alignment as a usize.

Trait Implementations§

Source§

impl Clone for Alignment

Source§

fn clone(&self) -> Alignment

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)
where Self:,

Performs copy-assignment from source. Read more
Source§

impl Copy for Alignment

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.