compact_rc/
lib.rs

1//! Low-memory reference-counting pointers.
2//!
3//! The types in this crate have almost the same methods as standard [Rc](std::rc::Rc) and
4//! [Arc](std::sync::Arc).
5//! The differences from the standard types are as follows:
6//!
7//! - Weak reference is not supported.
8//! - Small integers can be used as refcount.
9//!
10//! | Crate        | Strong count                       | Weak count    |
11//! | ------------ | ---------------------------------- | ------------- |
12//! | `std`        | `usize`                            | `usize`       |
13//! | `compact-rc` | `u8`, `u16`, `u32`, `u64`, `usize` | not supported |
14//!
15//! ## Example
16//! ```
17//! use compact_rc::Rc8;
18//!
19//! fn main() {
20//!     // rc1 is a pointer containing i8 value with u8 refcount.
21//!     let rc1: Rc8<i8> = Rc8::new(100);
22//!
23//!     assert_eq!(Rc8::strong_count(&rc1), 1);
24//!     assert_eq!(*rc1, 100);
25//!
26//!     // Increment the refcount.
27//!     // The value is shared by rc1 and rc2.
28//!     let rc2 = rc1.clone();
29//!
30//!     assert_eq!(Rc8::strong_count(&rc1), 2);
31//!     assert_eq!(Rc8::strong_count(&rc2), 2);
32//!     assert_eq!(*rc1, 100);
33//!     assert_eq!(*rc2, 100);
34//!     assert!(Rc8::ptr_eq(&rc1, &rc2));
35//! }
36//! ```
37#[macro_use]
38mod macros;
39mod base;
40
41pub mod arc;
42pub mod rc;
43pub mod refcount;
44
45pub use arc::Arc;
46pub use arc::Arc16;
47pub use arc::Arc32;
48pub use arc::Arc64;
49pub use arc::Arc8;
50
51pub use rc::Rc;
52pub use rc::Rc16;
53pub use rc::Rc32;
54pub use rc::Rc64;
55pub use rc::Rc8;