[−][src]Struct alloc_wg::alloc::NonZeroLayout
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 ofalign
, must not overflow (i.e., the rounded value must be less thanusize::MAX
).
#[must_use]
pub const unsafe fn from_size_align_unchecked(
size: NonZeroUsize,
align: NonZeroUsize
) -> Self
[src]
size: NonZeroUsize,
align: NonZeroUsize
) -> Self
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]
fn clone(&self) -> NonZeroLayout
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for NonZeroLayout
[src]
impl Eq for NonZeroLayout
[src]
impl PartialEq<NonZeroLayout> for NonZeroLayout
[src]
fn eq(&self, other: &NonZeroLayout) -> bool
[src]
fn ne(&self, other: &NonZeroLayout) -> bool
[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.
fn try_from(layout: Layout) -> Result<Self, Self::Error>
[src]
impl StructuralPartialEq for NonZeroLayout
[src]
impl StructuralEq for NonZeroLayout
[src]
Auto Trait Implementations
impl Send for NonZeroLayout
impl Sync for NonZeroLayout
impl Unpin for NonZeroLayout
impl UnwindSafe for NonZeroLayout
impl RefUnwindSafe for NonZeroLayout
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,