Expand description
§Flexible Array
The flex_array crate provides a #[no_std] flexible array similar to std::Vec, but with
greater control over memory usage. It allows customization of the types used for length,
capacity, and indexing operations, making it more efficient in certain use cases.
§Why Use FlexArr?
I wrote FlexArr to address some limitations of Rust’s standard std::Vec:
-
Reduced Memory Overhead: The
std::Vecon a 64-bit system typically uses 24 bytes. By specifying a smaller type for length and capacity (e.g.,u32),FlexArrcan reduce this to just 16 bytes, helping one optimizing memory usage. -
Fallible Allocations: Instead of panicking on allocation failure,
FlexArrreturns an error, allowing for more robust or graceful error handling. Whilestd::Vechas some fallible methods, most are still unstable. -
Custom Allocator Support: Since Rust’s allocator API is unstable,
FlexArrintroduces theAltAllocatortrait as an alternative to the standardAllocatortrait. If the the allocator API is stabilized, this will basically just become an an alias forAllocator.
§Feature Flags
-
std_alloc– Enables a wrapper calledGlobalthat implementsAltAllocatorusing the standard allocator APIs. -
alloc_unstable– Enables support for Rust’s unstableAllocatortrait for custom allocators. When used withstd_alloc, this re-exports theGlobaltype fromstdinstead of the custom wrapper namedGlobal. -
alloc_api2Enables support for theallocator-api2crate, which also provides anAllocatortrait in stable rust. This way if you already have allocators written against this you can use them with theflex_arraycrate. Note: This feature should not be enabled withalloc_unstablefeature. If you want to use both just able to enablealloc_unstableandnightlyin theallocator-api2crate. Additionally, if you are using thenightlyfeature of theallocator-api2crate you will need to enable thealloc_unstablefeature.
Modules§
- alloc
- Contains mainly allocator types and traits used by
FlexArrThe most important being theAltAllocatortrait, and theAllocErrortype. - types
- Contains types that are use by
FlexArrThe important types are theLengthTypeandFlexArrErr.
Structs§
- FlexArr
FlexArris a dynamic array that addresses some of the limitations of Rust’s standardVec.