| Crates.io | shared-vec |
| lib.rs | shared-vec |
| version | 0.1.0 |
| created_at | 2025-11-21 03:15:24.520627+00 |
| updated_at | 2025-11-21 03:15:24.520627+00 |
| description | Efficient shared container types |
| homepage | |
| repository | https://github.com/TheVeryDarkness/shared-vec.git |
| max_upload_size | |
| id | 1943037 |
| size | 66,571 |
shared-vecshared-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.
Vec<C, T>, where C is a counter type implementing the Counter trait.String<C>, where C is a counter type implementing the Counter trait.RcVec<T>, ArcVec<T>, RcString, and ArcString for ease of use.Add shared-vec to your Cargo.toml:
[dependencies]
shared-vec = "0.1"
Then, you can use the provided types in your Rust code:
use shared_vec::{RcVec, ArcString};
// Create
let vec: RcVec<i32> = RcVec::from_boxed_slice(Box::new([1, 2, 3]));
let string: ArcString = ArcString::from_boxed_str("Hello, world!".to_owned().into_boxed_str());
// Clone
let vec_clone = vec.clone();
let string_clone = string.clone();
// Access data
println!("{:?}", &vec[..]);
println!("{}", &string[..]);
// Borrow slices
let slice = vec.idx(1..3);
println!("{:?}", slice);
assert_eq!(slice.as_slice(), &[2, 3]);
let str_slice = string.idx(7..12);
println!("{:?}", str_slice);
assert_eq!(str_slice.as_str(), "world");
| 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 |