Skip to main content

Crate turbocow

Crate turbocow 

Source
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 to EcoVec<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 of EcoString for arbitrary [u8] data.
  • Macros: eco_vec!, eco_format!. Trait: ToEcoString.

§Maps & Sets

turbocow provides two families, optimised for different workloads:

TypeClone costBest for
EcoMap<K, V>O(1) — atomic refcount bumpClone-heavy, read-mostly
EcoSet<T>O(1)Clone-heavy, read-mostly
SmallMap<K, V, N>O(N) copyMutation-heavy, unique-owner
SmallSet<T, N>O(N) copyMutation-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 EcoString from a format string.
eco_vecallocator-api
Create a new EcoVec with the given elements.

Structs§

Globalallocator-api
The global memory allocator.