Skip to content

Commit bf69050

Browse files
committed
irc: Explain the benefits in the doc
1 parent a45817c commit bf69050

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/irc.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@
66
//! The underlayer of `Irc` is Box, unlike `Arc` which wrap a hidden ArcInner on your inner types,
77
//! Irc use the same memory location of your inner types.
88
//!
9-
//! [IrcItem::on_drop] in the trait allow you to have the ownship of underlying inner memory after the reference count of Irc is dropped.
9+
//! # Benefits
1010
//!
11-
//! # Example
11+
//! - No need to manual implementing the inc / dec on counter.
12+
//!
13+
//! - No enforced weak counter if you don't need it (every atomic op has cost).
14+
//!
15+
//! - [IrcItem::on_drop] in the trait allow you to have the ownship of underlying inner memory after the reference count of Irc is dropped. And you only need to define the drop behavior once, instead of write the same logic `Arc::into_inner` in every possible places (If forgetting so make your code block and hard to debug).
16+
//!
17+
//! - Using `Irc` to wrap a `Box`, no additional memory allocation and memory fragmentation, no
18+
//! additional dereference cost (than using `Arc<Box<T>>`)
19+
//!
20+
//! - You can allocate a box from the time of its birth and wrap it will `Irc` for temporary usage, don't need to move bytes from / to stack. (especially when the inner object is large)
21+
//!
22+
//! - Advanced usage, multiple layer customized counter, on the same heap object, while preserving
23+
//! the safe boundary
24+
//!
25+
//! # Example (Irc wrapping a Box)
1226
//!
1327
//! ```rust
1428
//! use embed_collections::irc::{Irc, IrcItem};

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//! - std `Box` (owned),
2222
//! - std `Arc`, `Rc` (multiple ownership)
2323
//! - [Irc](crate::irc): Highly customized Intrusive Reference Counter. See the detail in
24-
//! module doc.
24+
//! module doc.
2525
//! - [WaitGroupZeroGuard](https://docs.rs/crossfire/latest/crossfire/waitgroup/struct.WaitGroupZeroGuard.html): see the doc in `crossfire` crate
2626
//! - raw pointers (`NonNull<T>`, `*const T`, `*mut T`)
2727
//! - Structs:
@@ -148,7 +148,7 @@
148148
//!
149149
//! 2. Push `Box` to the list, the list own the items until they are popped, it's better than std
150150
//! LinkedList because no additional allocation is needed. It will not move the item
151-
//! in-and-out of hidden `Box` on every push / pop.
151+
//! in-and-out of hidden `Box` on every push / pop.
152152
//!
153153
//! 3. Push raw pointer (better use NonNull instead of *const T for smaller footprint) to the list,
154154
//! for temporary usage. You must ensure the list item not dropped be other refcount

0 commit comments

Comments
 (0)