Expand description
Allocation support for Müsli.
This crate contains two types of allocators:
- The
System
allocator, which uses the system allocation facilities. Particularlystd::alloc::System
. - The
Stack
allocator, which can allocate buffers from a fixed-size slice.
§Examples
use musli::{Allocator, Buf};
musli_allocator::with(|alloc| {
let mut a = alloc.alloc().expect("allocation a failed");
let mut b = alloc.alloc().expect("allocation b failed");
b.write(b"He11o");
a.write(b.as_slice());
assert_eq!(a.as_slice(), b"He11o");
assert_eq!(a.len(), 5);
a.write(b" W0rld");
assert_eq!(a.as_slice(), b"He11o W0rld");
assert_eq!(a.len(), 11);
let mut c = alloc.alloc().expect("allocation c failed");
c.write(b"!");
a.write(c.as_slice());
assert_eq!(a.as_slice(), b"He11o W0rld!");
assert_eq!(a.len(), 12);
});
Structs§
- Disabled
- An allocator which cannot allocate anything.
- Stack
- A no-std compatible fixed-memory allocator that can be used with the
musli
crate. - Stack
Buffer - A buffer that can be used to store data on the stack.
- System
alloc
- Buffer used in combination with an
Allocator
.
Constants§
- DEFAULT_
STACK_ BUFFER - The default stack buffer size for the default allocator provided through
with
.
Functions§
- with
- Call the given closure with the default allocator.
Type Aliases§
- Default
- The default allocator.