flex_alloc/
lib.rs

1//! Data structures with extra flexible storage.
2//!
3//! This crate provides highly flexible container types (currently
4//! [`Box`](crate::boxed::Box), [`Cow`](crate::borrow::Cow), and
5//! [`Vec`](crate::vec::Vec)) which mimic the API provided in `std`,
6//! with allocation flexibility going beyond what is supported by
7//! unstable features such as `allocator-api`.
8//!
9//! Both `no-std` and `no-alloc` environments are supported.
10//!
11//! ## Highlights
12//!
13//! - Optional `alloc` support, such that application may easily alternate between fixed buffers and heap allocation.
14//! - Custom allocator implementations, including the ability to spill from a small stack allocation to a heap allocation.
15//! - Additional fallible update methods, allowing for more ergonomic fixed size collections and handling of allocation errors.
16//! - `const` initializers.
17//! - Support for inline collections.
18//! - Custom index types and growth behavior to manage memory usage.
19//!
20//! ## Feature flags
21//!
22//! - The `std` flag (off by default) enables compatibility with the `std::error::Error` trait for error types, adds `io::Write` support to `Vec`, and also enables the `alloc` feature.
23//! - With the `alloc` feature (on by default), access to the global allocator is enabled, and default constructors for allocated containers (such as `Vec::new`) are supported.
24//! - The `allocator-api2` feature enables integration with the `allocator-api2` crate, which offers support for the `allocator-api` feature set on stable Rust. This can allow for allocators implementing the API to be passed to `Vec::new_in`.
25//! - The `nightly` feature enables compatibility with the unstable Rust `allocator-api` feature. This requires a nightly Rust compiler build.
26//! - The `zeroize` feature enables integration with the `zeroize` crate, including a zeroizing allocator. This can be used to automatically zero out allocated memory for allocated types, including the intermediate buffers produced during resizing in the case of `Vec`.
27
28#![cfg_attr(not(feature = "std"), no_std)]
29#![cfg_attr(feature = "nightly", feature(allocator_api, coerce_unsized, unsize))]
30#![warn(missing_docs)]
31
32#[doc = include_str!("../README.md")]
33#[cfg(doctest)]
34struct _ReadmeDoctests;
35
36#[cfg(test)]
37#[macro_use]
38extern crate std;
39
40#[cfg(feature = "alloc")]
41extern crate alloc as alloc_crate;
42
43pub mod alloc;
44
45pub mod boxed;
46
47pub mod borrow;
48
49pub mod capacity;
50
51pub(crate) mod error;
52
53pub mod storage;
54
55pub mod vec;
56
57pub use self::error::{StorageError, UpdateError};