Skip to main content

NonZeroLayout

Struct NonZeroLayout 

Source
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

Source

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.

Source

pub const fn from_size_align( size: usize, align: usize, ) -> Result<NonZeroLayout, LayoutError>

Construct from raw usize size and alignment. Convenience wrapper.

Source

pub const fn for_type<T>() -> Option<NonZeroLayout>

Layout for storing one T. Returns None if T is a ZST.

Source

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.

Source

pub const fn size(&self) -> NonZero<usize>

Size in bytes. Guaranteed nonzero.

Source

pub const fn align(&self) -> NonZero<usize>

Alignment in bytes. Guaranteed nonzero and a power of two.

Source

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.

Source

pub const fn to_layout(&self) -> Layout

Convert to a standard core::alloc::Layout. Always succeeds.

Trait Implementations§

Source§

impl Clone for NonZeroLayout

Source§

fn clone(&self) -> NonZeroLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for NonZeroLayout

Source§

impl Debug for NonZeroLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for NonZeroLayout

Source§

impl PartialEq for NonZeroLayout

Source§

fn eq(&self, other: &NonZeroLayout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for NonZeroLayout

Source§

impl TryFrom<Layout> for NonZeroLayout

Source§

type Error = LayoutError

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

fn try_from( value: Layout, ) -> Result<NonZeroLayout, <NonZeroLayout as TryFrom<Layout>>::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.