allocate/lib.rs
1//! Allocator-aware `Box`, `Vec`, `Arc`, `HashMap` and the `TalcAlloc`
2//! bridge — re-exported through a single workspace façade.
3//!
4//! ## Why this crate exists
5//!
6//! Stable Rust gives us 2-parameter `Box<T>` / `Vec<T>` / `Arc<T>`
7//! (defaulting to the global allocator), but the 3-parameter forms
8//! with a custom allocator are nightly-only. We want allocator-generic
9//! types so the shared talc-managed cache region can own everything
10//! (caps, refcounts, map storage) instead of half-talc-half-global.
11//!
12//! The fix is `allocator-api2 0.2` + `talc 4.x` + `hashbrown 0.17`
13//! (with their `allocator` / `allocator-api2` features). All three
14//! agree on a single `Allocator` trait —
15//! [`allocator_api2::alloc::Allocator`] — and Box / Vec / HashMap are
16//! all allocator-aware on stable. The only thing api2 doesn't ship is
17//! an `Arc`, so we provide one in [`sync`].
18//!
19//! Downstream depends on `allocate` only — no api2, talc, hashbrown,
20//! or spinning_top entries in any other crate's `Cargo.toml`.
21//!
22//! ## Module layout
23//!
24//! Module paths mirror `alloc::` where it makes sense:
25//!
26//! - [`boxed::Box<T, A>`] — re-export of `allocator_api2::boxed::Box`.
27//! - [`vec::Vec<T, A>`] — re-export of `allocator_api2::vec::Vec`.
28//! - [`collections::HashMap<K, V, A>`] — type-alias over
29//! `hashbrown::HashMap` with the default hasher.
30//! - [`sync::Arc<T, A>`] — own non-intrusive `Arc` (heap-header
31//! refcount, mirrors std `Arc`'s API).
32//! - [`talc`] — `TalcAlloc` / `CacheTalcLock` / talc re-exports.
33//!
34//! Plus, at the crate root:
35//!
36//! - [`Allocator`], [`Global`], [`AllocError`], [`Layout`] — re-exports
37//! of `allocator_api2::alloc::*`.
38
39#![cfg_attr(not(test), no_std)]
40
41extern crate alloc;
42
43pub use allocator_api2::alloc::{AllocError, Allocator, Global, Layout};
44
45pub mod boxed {
46 //! Re-export of `allocator_api2::boxed::Box`.
47 pub use allocator_api2::boxed::Box;
48}
49
50pub mod vec {
51 //! Re-export of `allocator_api2::vec::Vec`.
52 pub use allocator_api2::vec::Vec;
53}
54
55pub mod collections;
56pub mod sync;
57pub mod talc;
58
59#[cfg(test)]
60pub mod test_arena;
61
62#[cfg(test)]
63mod boxed_tests;
64#[cfg(test)]
65mod sync_tests;
66#[cfg(test)]
67mod vec_tests;