Expand description
Compact, clone-on-write collections — a strict superset of ecow 0.3.0.
turbocow extends ecow with additional data structures and a zero-copy
Referenced storage variant. Existing ecow code works by swapping the crate:
replace ecow with turbocow in Cargo.toml and update the imports from
ecow::EcoVec / ecow::EcoString to turbocow::EcoVec / turbocow::EcoString.
§Types
§Vectors & Strings
EcoVec<T>— compact (2-word) reference-counted clone-on-write vector; same layout as&[T].EcoString— clone-on-write string, 15 bytes inline, spills toEcoVec<u8>; fully owns its data.EcoStr<'a>— lifetime-carrying string; supports a zero-copy Referenced (borrowed) storage variant;EcoString = EcoStr<'static>(owned).EcoByteString— byte-oriented counterpart ofEcoStringfor arbitrary[u8]data.- Macros:
eco_vec!,eco_format!. Trait:ToEcoString.
§Maps & Sets
turbocow provides two families, optimised for different workloads:
| Type | Clone cost | Best for |
|---|---|---|
EcoMap<K, V> | O(1) — atomic refcount bump | Clone-heavy, read-mostly |
EcoSet<T> | O(1) | Clone-heavy, read-mostly |
SmallMap<K, V, N> | O(N) copy | Mutation-heavy, unique-owner |
SmallSet<T, N> | O(N) copy | Mutation-heavy, unique-owner |
SmallVec<'a, T, N> is an inline-storage vec (N slots on the stack, spills to heap)
with its own zero-copy Referenced variant.
See the README for feature flags.
§Example
// This is stored inline.
let small = turbocow::EcoString::from("Welcome");
// This spills to the heap, but only once: `big` and `third` share the
// same underlying allocation. Vectors and spilled strings are only
// really cloned upon mutation.
let big = small + " to earth! 🌱";
let mut third = big.clone();
// This allocates again to mutate `third` without affecting `big`.
assert_eq!(third.pop(), Some('🌱'));
assert_eq!(third, "Welcome to earth! ");Re-exports§
pub use self::eco_map::EcoMap;pub use self::eco_set::EcoSet;pub use self::small_map::SmallMap;pub use self::small_set::SmallSet;pub use self::small_vec::SmallVec;pub use self::string::EcoByteString;pub use self::string::EcoStr;pub use self::string::EcoString;pub use self::string::ToEcoString;pub use self::vec::EcoVec;pub use self::vec::IntoIter;
Modules§
- eco_map
- Refcounted, copy-on-write map backed by two
EcoVecs. - eco_set
- Refcounted, copy-on-write set backed by an
EcoMap. - small_
map - Compact, inline-optimized hash map.
- small_
set - Compact, inline-optimized hash set.
- small_
vec - Inline-spillable vector for arbitrary
Ts. - string
- A clone-on-write, small-string-optimized alternative to
String. - vec
- A clone-on-write alternative to
Vec.
Macros§
- eco_
format - Create a new
EcoStringfrom a format string. - eco_vec
allocator-api - Create a new
EcoVecwith the given elements.
Structs§
- Global
allocator-api - The global memory allocator.