[][src]Struct alloc_wg::alloc::NonZeroLayout

pub struct NonZeroLayout { /* fields omitted */ }

Non-zero Layout of a block of memory.

An instance of NonZeroLayout describes a particular layout of memory. You build a NonZeroLayout up as an input to give to an allocator.

All layouts have an associated non-negative size and a power-of-two alignment.

Methods

impl NonZeroLayout[src]

pub fn from_size_align(size: usize, align: usize) -> Result<Self, LayoutErr>[src]

Constructs a Layout from a given size and align, or returns LayoutErr if either of the following conditions are not met:

  • align must not be zero,
  • align must be a power of two,
  • size must not be zero,
  • size, when rounded up to the nearest multiple of align, must not overflow (i.e., the rounded value must be less than usize::MAX).

#[must_use] pub const unsafe fn from_size_align_unchecked(
    size: NonZeroUsize,
    align: NonZeroUsize
) -> Self
[src]

Creates a layout, bypassing all checks.

Safety

This function is unsafe as it does not verify the preconditions from NonZeroLayout::from_size_align.

#[must_use] pub const fn size(&self) -> NonZeroUsize[src]

The minimum size in bytes for a memory block of this layout.

#[must_use] pub const fn align(&self) -> NonZeroUsize[src]

The minimum byte alignment for a memory block of this layout.

pub fn new<T>() -> Result<Self, LayoutErr>[src]

Constructs a NonZeroLayout suitable for holding a value of type T.

Returns Err if T is a ZST.

#[must_use] pub const unsafe fn new_unchecked<T>() -> Self[src]

Constructs a NonZeroLayout suitable for holding a value of type T.

Safety

This function is unsafe as it does not verify the preconditions from NonZeroLayout::new.

pub fn for_value<T: ?Sized>(t: &T) -> Option<Self>[src]

Produces layout describing a record that could be used to allocate backing structure for T (which could be a trait or other unsized type like a slice).

Returns None if T is a ZST.

#[must_use] pub const fn padding_needed_for(&self, align: NonZeroUsize) -> usize[src]

Returns the amount of padding we must insert after self to ensure that the following address will satisfy align (measured in bytes).

e.g., if self.size() is 9, then self.padding_needed_for(4) returns 3, because that is the minimum number of bytes of padding required to get a 4-aligned address (assuming that the corresponding memory block starts at a 4-aligned address).

The return value of this function has no meaning if align is not a power-of-two.

Note that the utility of the returned value requires align to be less than or equal to the alignment of the starting address for the whole allocated block of memory. One way to satisfy this constraint is to ensure align <= self.align().

pub unsafe fn for_value_unchecked<T: ?Sized>(t: &T) -> Self[src]

Produces layout describing a record that could be used to allocate backing structure for T (which could be a trait or other unsized type like a slice).

Safety

This function is unsafe as it does not verify the preconditions from NonZeroLayout::for_value.

pub fn repeat(&self, n: NonZeroUsize) -> Result<(Self, NonZeroUsize), LayoutErr>[src]

Creates a layout describing the record for n instances of self, with a suitable amount of padding between each to ensure that each instance is given its requested size and alignment. On success, returns (k, offs) where k is the layout of the array and offs is the distance between the start of each element in the array.

On arithmetic overflow, returns LayoutErr.

pub fn array<T>(n: NonZeroUsize) -> Result<Self, LayoutErr>[src]

Creates a layout describing the record for a [T; n].

On arithmetic overflow, returns LayoutErr.

Trait Implementations

impl Into<Layout> for NonZeroLayout[src]

impl Clone for NonZeroLayout[src]

impl Copy for NonZeroLayout[src]

impl Eq for NonZeroLayout[src]

impl PartialEq<NonZeroLayout> for NonZeroLayout[src]

impl Debug for NonZeroLayout[src]

impl TryFrom<Layout> for NonZeroLayout[src]

type Error = LayoutErr

The type returned in the event of a conversion error.

impl StructuralPartialEq for NonZeroLayout[src]

impl StructuralEq for NonZeroLayout[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]