[][src]Struct alloc_compose::Region

pub struct Region<'a> { /* fields omitted */ }

Allocator over an user-defined region of memory.

Examples

#![feature(allocator_api)]

use alloc_compose::{Owns, Region};
use core::alloc::{AllocInit, AllocRef, Layout};

let mut data = [0; 64];
let mut region = Region::new(&mut data);

let memory = region.alloc(Layout::new::<u32>(), AllocInit::Uninitialized)?;
assert!(region.owns(memory));

It's possible to deallocate the latest memory block allocated:

unsafe { region.dealloc(memory.ptr, Layout::new::<u32>()) };
assert!(!region.owns(memory));

Methods

impl<'a> Region<'a>[src]

pub fn new(data: &'a mut [u8]) -> Self[src]

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

Returns the total capacity available in this allocator.

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

Returns the free capacity left for allocating.

pub fn reset(&mut self)[src]

Resets the allocator.

This implies, that capacity() and capacity_left() are equal afterwards.

pub fn is_last_block(&self, memory: MemoryBlock) -> bool[src]

Checks if memory is the latest block, which was allocated. For those blocks, it's possible to deallocate them or to grow or shrink them in place.

Trait Implementations

impl<'_> AllocRef for Region<'_>[src]

impl<'_> Debug for Region<'_>[src]

impl<'_> Owns for Region<'_>[src]

Auto Trait Implementations

impl<'a> Send for Region<'a>

impl<'a> Sync for Region<'a>

impl<'a> Unpin for Region<'a>

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.