1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*!
Compact, clone-on-write collections — a strict superset of [`ecow`][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:
| 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! ");
```
[ecow]: https://github.com/typst/ecow
*/
// See https://github.com/tokio-rs/loom/issues/352
extern crate alloc;
pub
pub use EcoMap;
pub use EcoSet;
pub use SmallMap;
pub use SmallSet;
pub use SmallVec;
pub use ;
pub use ;
// Re-export allocator types when features are enabled
pub use Global;
// Run doctests on the README too
;
/// Loom needs its own synchronization types to be used in order to work