shared-vec
shared-vec is a Rust crate that provides immutable reference-counted vector and string types allowing sharing data (or even a part of it) without lifetime-bound references.
Features
- Immutable reference-counted vector type
Vec<C, T>, whereCis a counter type implementing theCountertrait. - Immutable reference-counted string type
String<C>, whereCis a counter type implementing theCountertrait. - Common type aliases
RcVec<T>,ArcVec<T>,RcString, andArcStringfor ease of use. - Safe and efficient memory management with customizable reference counting strategies.
Usage
Add shared-vec to your Cargo.toml:
[]
= "0.1"
Then, you can use the provided types in your Rust code:
use ;
// Create
let vec: = from_boxed_slice;
let string: ArcString = from_boxed_str;
// Clone
let vec_clone = vec.clone;
let string_clone = string.clone;
// Access data
println!;
println!;
// Borrow slices
let slice = vec.idx;
println!;
assert_eq!;
let str_slice = string.idx;
println!;
assert_eq!;
Related Projects
| Crate Name | Description | Memory Management Approach | deref or as_str |
Offset Representation | Allow Weak References |
|---|---|---|---|---|---|
substr |
Substrings as ranges | no allocation | N | usize |
|
genrc |
Ref-counted pointers allowing to reference subobjects | reference counting | Y | std::ptr::NonNull<T> |
Y |
shared-string |
Shared strings backed by Rc<Box<[u8]>> and Arc<Box<[u8]>> |
reference counting | Y | usize |
N |
shared_slice |
Shared slices backed by Rc<()> and Arc<()> |
reference counting | Y | usize |
N |
shared-vec |
Ref-counted vectors and strings simulating Rc and Arc |
reference counting | *const [T] |
Y | |
&str |
lifetime | data part of the fat pointer |