15 releases
| 0.1.14 | Jul 11, 2025 |
|---|---|
| 0.1.13 | Jul 11, 2025 |
| 0.1.6 | Jun 19, 2025 |
#1142 in Data structures
515 downloads per month
Used in offset-vec
69KB
2K
SLoC
RcVec based on Rc and can be converted from Rc without allocation,
just like Box is converted to Vec
Due to Rc's API, this implementation cannot use realloc, resulting in some performance issues
Similar to Vec::into_boxed_slice,
RcVec::into_uniq_slice can be converted to UniqRc,
which is the packaging of Rc and behaves similarly to Box
Examples
use rc_vec::RcVec;
use std::rc::Rc;
let rc: Rc<[i32]> = Rc::new([1, 2, 3]);
let rcptr = Rc::as_ptr(&rc).cast();
let mut vec = RcVec::from(rc);
assert_eq!(vec.len(), 3);
assert_eq!(vec.capacity(), 3);
assert!(std::ptr::eq(rcptr, vec.as_ptr()));
vec.push(4);
assert_eq!(vec.len(), 4);
assert!(vec.capacity() > 3);
assert!(! std::ptr::eq(rcptr, vec.as_ptr()));
assert_eq!(vec, [1, 2, 3, 4]);
Safety
- miri passed
I have not checked any synchronization related issues with the Arc variant
Dependencies
~165KB