Expand description
memapi provides a minimal, no_std-friendly memory allocation interface
for managing raw buffers, suitable for use in collections.
This crate exports:
Alloc, a trait defining basic allocate, deallocate, grow, and shrink operations.DefaultAlloc, a zero-cost wrapper delegating to the global allocator.AllocError, an enum of possible error cases.PtrProps, properties getters for pointers to values.- [
SizedProps], properties for sized types. Similar to the unstableSizedTypeProperties.
And, if the alloc_ext feature is on:
AllocExt, defining abstractions over Alloc’s API.UnsizedCopy, a marker trait indicating a value can be copied safely even if unsized.
§Examples
let allocator = DefaultAlloc;
// Allocate 4 usizes.
let ptr: NonNull<usize> = allocator.alloc_count::<usize>(4).expect("alloc failed");
unsafe {
for i in 0..4 {
ptr.add(i).write(17384 * i + 8923)
}
}
// Deallocate the block.
unsafe { allocator.dealloc_n(ptr, 4) };Modules§
Structs§
- Default
Alloc - Default allocator, delegating to the global allocator.
Enums§
- Alloc
Error - Errors for allocation operations.
Traits§
- Alloc
- A minimal memory allocation interface.
- Alloc
Ext - Extension methods for the core
Alloctrait, providing convenient routines to allocate, initialize, clone, copy, and deallocate sized and unsized types. - Unsized
Copy - Unsafe marker trait for types that can be copied, including unsized types such as slices.