8 releases

0.5.5 May 4, 2024
0.5.4 Mar 26, 2024
0.5.2 Jun 4, 2023
0.5.0 May 27, 2023
0.3.1 May 3, 2023

#365 in Data structures

Download history 53/week @ 2024-03-07 65/week @ 2024-03-14 142/week @ 2024-03-21 133/week @ 2024-03-28 281/week @ 2024-04-04 554/week @ 2024-04-11 678/week @ 2024-04-18 111/week @ 2024-04-25 266/week @ 2024-05-02 215/week @ 2024-05-09 32/week @ 2024-05-16 32/week @ 2024-05-23 43/week @ 2024-05-30 8/week @ 2024-06-06 9/week @ 2024-06-13 9/week @ 2024-06-20

71 downloads per month
Used in duplink

MIT/Apache

63KB
2K SLoC

compact-rc

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:

  • Weak reference is not supported.
  • Small integers can be used as refcount.
Crate Strong count Weak count
std usize usize
compact-rc u8, u16, u32, u64, usize not supported

Example

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));
}

No runtime deps