Crate memapi

Source
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 unstable SizedTypeProperties.

  • UnsizedCopy, a marker trait indicating a value can be copied safely even if unsized.

  • Thin, a marker trait indicating a pointer to a type has no metadata.

And, if the alloc_ext feature is on:

  • AllocExt, defining abstractions over Alloc’s API.

§Examples

let allocator = DefaultAlloc;
// Allocate 4 usizes.
let ptr = allocator.alloc_slice::<usize>(4).expect("alloc failed").cast::<usize>();
unsafe {
    for i in 0..4 {
        ptr.add(i).write(17384 * i + 8923)
    }
}
// Deallocate the block.
unsafe { allocator.dealloc_n(ptr, 4) };

Modules§

helpers
Helpers which tend to be useful in other libraries as well.
stats
Allocation statistic gathering and reporting.
unstable_util
Small alternatives to Rust functions which are currently unstable.

Structs§

DefaultAlloc
Default allocator, delegating to the global allocator.

Enums§

AllocError
Errors for allocation operations.

Traits§

Alloc
A memory allocation interface.
AllocExt
Extension methods for the core Alloc trait, providing convenient routines to allocate, initialize, clone, copy, and deallocate sized and unsized types.
PtrProps
A trait providing methods for pointers to provide the properties of their pointees.
SizedProps
A trait containing constants for sized types.
Thin
Trait indicating that a type has no metadata.
UnsizedCopy
Unsafe marker trait for types that can be copied, including unsized types such as slices.