Skip to main content

Layout

Struct Layout 

1.28.0 · Source
pub struct Layout { /* private fields */ }
Expand description

Layout of a block of memory.

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

All layouts have an associated size and a power-of-two alignment. The size, when rounded up to the nearest multiple of align, does not overflow isize (i.e., the rounded value will always be less than or equal to isize::MAX).

(Note that layouts are not required to have non-zero size, even though GlobalAlloc requires that all memory requests be non-zero in size. A caller must either ensure that conditions like this are met, use specific allocators with looser requirements, or use the more lenient Allocator interface.)

Implementations§

Source§

impl Layout

1.28.0 (const: 1.36.0) · Source

pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self

Creates a layout, bypassing all checks.

§Safety

This function is unsafe as it does not verify the preconditions from [Layout::from_size_align].

Source

pub const unsafe fn from_size_alignment_unchecked( size: usize, alignment: Alignment, ) -> Self

🔬This is a nightly-only experimental API. (ptr_alignment_type #102070)

Creates a layout, bypassing all checks.

§Safety

This function is unsafe as it does not verify the preconditions from [Layout::from_size_alignment].

1.28.0 (const: 1.50.0) · Source

pub const fn size(&self) -> usize

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

1.28.0 (const: 1.50.0) · Source

pub const fn align(&self) -> usize

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

The returned alignment is guaranteed to be a power of two.

1.28.0 (const: 1.42.0) · Source

pub const fn new<T>() -> Self

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

Trait Implementations§

1.28.0 · Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
1.28.0 · Source§

impl Debug for Layout

Source§

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

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

impl Hash for Layout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
where Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
1.28.0 · Source§

impl PartialEq for Layout

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
1.28.0 · Source§

impl Copy for Layout

1.28.0 · Source§

impl Eq for Layout

1.28.0 · Source§

impl StructuralPartialEq for Layout

Auto Trait Implementations§

§

impl Freeze for Layout

§

impl Send for Layout

§

impl Sync for Layout

§

impl Unpin for Layout

Blanket Implementations§

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> 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, 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.