[][src]Crate bump_into

A no_std bump allocator sourcing space from a user-provided mutable slice rather than from a global allocator, making it suitable for use in embedded applications and tight loops.

Example

use bump_into::{self, BumpInto};

// allocate 64 bytes of uninitialized space on the stack
let mut bump_into_space = bump_into::space_uninit!(64);
let bump_into = BumpInto::from_slice(&mut bump_into_space[..]);

// allocating an object produces a mutable reference with
// a lifetime borrowed from `bump_into_space`, or gives
// back its argument in `Err` if there isn't enough space
let number: &mut u64 = bump_into
    .alloc_with(|| 123)
    .ok()
    .expect("not enough space");
assert_eq!(*number, 123);
*number = 50000;
assert_eq!(*number, 50000);

// slices can be allocated as well
let slice: &mut [u16] = bump_into
    .alloc_n_with(5, core::iter::repeat(10))
    .expect("not enough space");
assert_eq!(slice, &[10; 5]);
slice[2] = 100;
assert_eq!(slice, &[10, 10, 100, 10, 10]);

Macros

space_uninit

Creates an uninitialized array of MaybeUninit without allocating, suitable for taking a slice of to pass into BumpInto::from_slice.

space_uninit_aligned

Creates an uninitialized array of one MaybeUninit without allocating, with the given size and alignment, suitable for taking a slice of to pass into BumpInto::from_slice. The size will be rounded up to the nearest multiple of the given alignment.

space_zeroed

Creates a zeroed array of MaybeUninit without allocating, suitable for taking a slice of to pass into BumpInto::from_slice.

space_zeroed_aligned

Creates a zeroed array of one MaybeUninit without allocating, with the given size and alignment, suitable for taking a slice of to pass into BumpInto::from_slice. The size will be rounded up to the nearest multiple of the given alignment.

Structs

AlignOf

A zero-sized struct that becomes core::mem::align_of::<T>() when converted using Into<usize>.

BumpInto

A bump allocator sourcing space from an &mut [MaybeUninit].

SizeOf

A zero-sized struct that becomes core::mem::size_of::<T>() when converted using Into<usize>.