pub struct NonZeroLayout { /* private fields */ }Expand description
A Layout with size > 0 and a power-of-two alignment.
All primitives in this crate take NonZeroLayout rather than Layout. ZST
handling happens once, at the StdCompat boundary, instead of being
reinvented in every implementor.
Implementations§
Source§impl NonZeroLayout
impl NonZeroLayout
Sourcepub const fn new(
size: NonZero<usize>,
align: NonZero<usize>,
) -> Result<NonZeroLayout, LayoutError>
pub const fn new( size: NonZero<usize>, align: NonZero<usize>, ) -> Result<NonZeroLayout, LayoutError>
Construct from a non-zero size and non-zero alignment.
Returns LayoutError if align is not a power of two or if rounding
size up to align would overflow isize::MAX.
Sourcepub const fn from_size_align(
size: usize,
align: usize,
) -> Result<NonZeroLayout, LayoutError>
pub const fn from_size_align( size: usize, align: usize, ) -> Result<NonZeroLayout, LayoutError>
Construct from raw usize size and alignment. Convenience wrapper.
Sourcepub const fn for_type<T>() -> Option<NonZeroLayout>
pub const fn for_type<T>() -> Option<NonZeroLayout>
Layout for storing one T. Returns None if T is a ZST.
Sourcepub const fn array<T>(n: usize) -> Option<NonZeroLayout>
pub const fn array<T>(n: usize) -> Option<NonZeroLayout>
Layout for an array of n Ts. Returns None if T is a ZST,
n is zero, or the resulting size overflows.
Mirrors core::alloc::Layout::array::<T>(n)’s padding rules: each
element is padded out to align_of::<T>() (which size_of::<T>()
already encodes via the trailing-pad rule, so for sized types the
product is identical). The explicit pad_to_align step keeps the
math correct if a future repr ever lets size_of skip the
trailing pad — #[repr(C, packed)] types stay correct because
their align is 1 and pad_to_align is a no-op.
Sourcepub const fn align(&self) -> NonZero<usize>
pub const fn align(&self) -> NonZero<usize>
Alignment in bytes. Guaranteed nonzero and a power of two.
Sourcepub const fn pad_to_align(&self) -> NonZeroLayout
pub const fn pad_to_align(&self) -> NonZeroLayout
Round size up so the layout’s total footprint is a multiple of
align. Useful for packing arrays of this layout end-to-end.
Trait Implementations§
Source§impl Clone for NonZeroLayout
impl Clone for NonZeroLayout
Source§fn clone(&self) -> NonZeroLayout
fn clone(&self) -> NonZeroLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for NonZeroLayout
Source§impl Debug for NonZeroLayout
impl Debug for NonZeroLayout
impl Eq for NonZeroLayout
Source§impl PartialEq for NonZeroLayout
impl PartialEq for NonZeroLayout
Source§fn eq(&self, other: &NonZeroLayout) -> bool
fn eq(&self, other: &NonZeroLayout) -> bool
self and other values to be equal, and is used by ==.