|0.1.2||Aug 19, 2023|
|0.1.1||Apr 16, 2023|
|0.1.0||Mar 1, 2023|
#136 in Data structures
4,531 downloads per month
Used in 11 crates (3 directly)
Compact, clone-on-write vector and string.
EcoVecis a reference-counted clone-on-write vector. It takes up two words of space (= 2 usize) and has the same memory layout as a
&[T]slice. Within its allocation, it stores a reference count, its capacity and its elements.
EcoStringis a reference-counted clone-on-write string with inline storage. It takes up 16 bytes of space. It has 15 bytes of inline storage and starting from 16 bytes it becomes an
// This is stored inline. let small = ecow::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! ");
Why should I use this instead of ...
||Normal vectors are a great general purpose data structure. But they have a quite big footprint (3 machine words) and are expensive to clone. The
||These require two allocations instead of one and are less convenient to mutate.|
||While these require only one allocation, they aren't mutable.|
|Small vector||Different trade-off. Great when there are few, small
This crate is dual-licensed under the MIT and Apache 2.0 licenses.