rc-vec

Crates.iorc-vec
lib.rsrc-vec
version0.1.14
created_at2025-06-18 14:44:02.92375+00
updated_at2025-07-11 03:41:48.676041+00
descriptionRcVec based on Rc and can be converted from Rc without allocation
homepage
repositoryhttps://github.com/A4-Tacks/rc-vec-rs
max_upload_size
id1717203
size87,710
A4-Tacks (A4-Tacks)

documentation

README

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

Commit count: 10

cargo fmt