Crate shared_vec

Crate shared_vec 

Source
Expand description

§shared-vec

codecov

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>, where C is a counter type implementing the Counter trait.
  • Immutable reference-counted string type String<C>, where C is a counter type implementing the Counter trait.
  • Common type aliases RcVec<T>, ArcVec<T>, RcString, and ArcString for ease of use.
  • Safe and efficient memory management with customizable reference counting strategies.

§Usage

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 NameDescriptionMemory Management Approachderef or as_strOffset RepresentationAllow Weak References
substrSubstrings as rangesno allocationNusize
genrcRef-counted pointers allowing to reference subobjectsreference countingYstd::ptr::NonNull<T>Y
shared-stringShared strings backed by Rc<Box<[u8]>> and Arc<Box<[u8]>>reference countingYusizeN
shared_sliceShared slices backed by Rc<()> and Arc<()>reference countingYusizeN
shared-vecRef-counted vectors and strings simulating Rc and Arcreference counting*const [T]Y
&strlifetimedata part of the fat pointer

Structs§

String
An immutable reference-counted string type.
Vec
An immutable reference-counted vector type.

Traits§

Counter
Counter trait for uniformed reference counting.

Type Aliases§

ArcString
Type alias for an atomically reference-counted String using AtomicUsize as the counter.
ArcVec
Type alias for an atomically reference-counted Vec using AtomicUsize as the counter.
RcString
Type alias for a reference-counted String using Cell<usize> as the counter.
RcVec
Type alias for a reference-counted Vec using Cell<usize> as the counter.