without_alloc/lib.rs
1//! Dynamic data structures that do not require a global allocator.
2//!
3//! The most directly useful might be a local `FixedVec` that requires its element to be neither
4//! `Clone`, `Copy` nor `Default` but is simply a normal vector on a locally borrowed chunk of raw
5//! memory. For this we will use the `Bump` allocator of [`static-alloc`] which loan us memory from
6//! the stack and cleans up by leaving the scope without requiring explicit deallocation. Sort of
7//! like `alloca` but safe and pretty.
8//!
9//! [`static-alloc`]: https://crates.io/crates/static-alloc
10//!
11//! ```rust
12//! use static_alloc::Bump;
13//! use without_alloc::{FixedVec, alloc::LocalAllocLeakExt};
14//!
15//! let mut pool: Bump<[usize; 16]> = Bump::uninit();
16//! // Allocate a vector with capacity of 16 from the slab.
17//! let mut vector = pool.fixed_vec(16).unwrap();
18//!
19//! let mut num = 0;
20//! // Push a mutable reference, not `Copy` nor `Clone`!
21//! vector.push(&mut num);
22//!
23//! *vector.pop().unwrap() = 4;
24//! drop(vector);
25//!
26//! assert_eq!(num, 4);
27//! ```
28// Copyright 2019–2020 Andreas Molzer
29#![no_std]
30#![deny(missing_docs)]
31#![cfg_attr(feature = "nightly_set_ptr_value", feature(set_ptr_value))]
32
33pub mod alloc;
34pub mod boxed;
35pub mod rc;
36pub mod uninit;
37pub mod fixed_vec;
38
39pub use boxed::Box;
40pub use fixed_vec::FixedVec;
41pub use uninit::Uninit;