Crates.io | compact-rc |
lib.rs | compact-rc |
version | 0.5.5 |
source | src |
created_at | 2023-05-03 18:20:40.464973 |
updated_at | 2024-05-04 18:42:28.999183 |
description | Low-memory reference-counting pointers |
homepage | |
repository | https://github.com/akmizno/compact-rc |
max_upload_size | |
id | 855686 |
size | 75,361 |
Low-memory reference-counting pointers.
The types in this crate have almost the same methods as standard Rc
and Arc
.
The differences from the standard type are as follows:
Crate | Strong count | Weak count |
---|---|---|
std |
usize |
usize |
compact-rc |
u8 , u16 , u32 , u64 , usize |
not supported |
use compact_rc::Rc8;
fn main() {
// rc1 is a pointer containing i8 value with u8 refcount.
let rc1: Rc8<i8> = Rc8::new(100);
assert_eq!(Rc8::strong_count(&rc1), 1);
assert_eq!(*rc1, 100);
// Increment the refcount.
// The value is shared by rc1 and rc2.
let rc2 = rc1.clone();
assert_eq!(Rc8::strong_count(&rc1), 2);
assert_eq!(Rc8::strong_count(&rc2), 2);
assert_eq!(*rc1, 100);
assert_eq!(*rc2, 100);
assert!(Rc8::ptr_eq(&rc1, &rc2));
}