[][src]Struct alloc_wg::alloc::MemoryBlock

#[must_use = "`MemoryBlock` should be passed to `AllocRef::dealloc`"]pub struct MemoryBlock { /* fields omitted */ }

Represents a block of allocated memory returned by an allocator.

Methods

impl MemoryBlock[src]

pub const unsafe fn new(ptr: NonNull<u8>, layout: Layout) -> Self[src]

Creates a new MemoryBlock.

Safety

  • The block must be allocated with the same alignment as [layout.align()], and
  • The provided [layout.size()] must fall in the range min ..= max, where:
    • min is the size requested size when allocating the block, and
    • max is the size of the memory block.

pub const fn ptr(&self) -> NonNull<u8>[src]

Acquires the underlying NonNull<u8> pointer.

pub const fn layout(&self) -> Layout[src]

Returns the layout describing the memory block.

pub const fn size(&self) -> usize[src]

Returns the size of the memory block.

pub const fn align(&self) -> usize[src]

Returns the minimum alignment of the memory block.

pub fn init(&mut self, init: AllocInit)[src]

Initialize the memory block like specified by init.

This behaves like calling MemoryBlock::initialize_offset(ptr, layout, 0).

pub unsafe fn init_offset(&mut self, init: AllocInit, offset: usize)[src]

Initialize the memory block like specified by init at the specified offset.

This is a no-op for AllocInit::Uninitialized and writes zeroes for AllocInit::Zeroed at ptr + offset until ptr + layout.size().

Safety

  • offset must be smaller than or equal to size()

Trait Implementations

impl Debug for MemoryBlock[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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.