| Crates.io | musli-allocator |
| lib.rs | musli-allocator |
| version | 0.0.117 |
| created_at | 2024-03-20 01:27:44.169845+00 |
| updated_at | 2024-04-20 08:46:49.182487+00 |
| description | Allocators for Müsli. |
| homepage | https://github.com/udoprog/musli |
| repository | https://github.com/udoprog/musli |
| max_upload_size | |
| id | 1179882 |
| size | 53,723 |
Allocation support for Müsli.
This crate contains two types of allocators:
System] allocator, which uses the system allocation facilities.
Particularly std::alloc::System.Stack] allocator, which can allocate buffers from a fixed-size
slice.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);
});