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
impl Alignment
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.
Sourcepub const unsafe fn new_unchecked(align: usize) -> Self
🔬This is a nightly-only experimental API. (ptr_alignment_type
#102070)
pub const 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.