Skip to main content

Crate memapi2

Crate memapi2 

Source
Expand description

A small, no_std/no_alloc-friendly memory allocation interface for managing raw buffers.

This crate provides explicit layouts, a split allocator trait stack, and structured errors. It is no_std by default but relies on the alloc crate unless no_alloc is enabled. Enable std for system allocator integrations and os_err_reporting for richer diagnostics.

§Core traits

§Types and errors

  • Layout: crate layout type (with conversion to/from StdLayout unless no_alloc is enabled)
  • DefaultAlloc: default allocator wrapper that delegates to the global allocator
  • Errors: [Error], [Cause], [LayoutErr], [ArithErr], [ArithOp]

§Data and type utilities

§Allocator implementations

§Feature flags

  • std: enables std integration (including std::alloc::System)
  • os_err_reporting: best-effort OS error reporting via errno (requires std)
  • alloc_mut_traits: mutable allocator trait variants
  • alloc_temp_trait: scoped/temporary allocation trait
  • c_alloc: C aligned_alloc-style allocator (c_alloc)
  • stack_alloc: alloca-based allocator (stack_alloc)
  • c_str: enables CStr-specific data traits in no_std (MSRV: 1.64)
  • metadata: enables core::ptr::Pointee metadata support on nightly
  • sized_hierarchy: enables core::marker::MetaSized support on nightly
  • full, full_nightly: convenience bundles for docs/tests

Re-exports§

pub use traits::*;

Modules§

c_alloc
An allocator which uses C’s aligned_alloc set of allocation functions.
error
Errors that can occur during allocation.
helpers
Helpers that tend to be useful in other libraries as well.
stack_alloc
An allocator which uses C’s alloca/_alloca allocation function.
traits
The library’s main traits.

Structs§

DefaultAlloc
Default allocator, delegating to the global allocator.
Layout
The layout of a block of memory in the form of its size and alignment in bytes.

Type Aliases§

StdLayout
A type alias for alloc::alloc::Layout.