pub struct Alignment {
pub power: u8,
}Expand description
Alignment of a type or value.
It is stored as its power of two, so the compiler knows that the alignment in bytes is a power
of two, and code that uses it can compute padding with plain % that compiles to bit masks.
Alignments compare like their values in bytes.
Fields§
§power: u8Power of two of the alignment, at most the power of Alignment::MAX
Implementations§
Source§impl Alignment
impl Alignment
Sourcepub const MAX: Self
pub const MAX: Self
The largest alignment supported, 16 bytes.
No TrivialType has a larger alignment.
Sourcepub const fn from_power(power: u8) -> Option<Self>
pub const fn from_power(power: u8) -> Option<Self>
Alignment from its power of two, None if it would be larger than Alignment::MAX
Sourcepub const fn of<T>() -> Selfwhere
T: TrivialType,
pub const fn of<T>() -> Selfwhere
T: TrivialType,
Alignment of T in metadata, see TrivialType::ALIGNMENT.
TrivialType requires an alignment of at most Alignment::MAX, and a call doesn’t
compile for an implementation that breaks this requirement. It also doesn’t compile when
T::ALIGNMENT is smaller than align_of::<T>().
Sourcepub fn is_slice_aligned<T>(self, slice: &[T]) -> boolwhere
T: TrivialType,
pub fn is_slice_aligned<T>(self, slice: &[T]) -> boolwhere
T: TrivialType,
Whether slice starts at an address aligned to self