From c64a34eb4799bffcf0ad04461954d5ba0a94e562 Mon Sep 17 00:00:00 2001 From: Mark Hayes Date: Sat, 12 Apr 2025 18:31:07 -0700 Subject: [PATCH] Doc the benefits of Send for RcBox --- crates/rc-box/README.md | 4 ++++ crates/rc-box/src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/crates/rc-box/README.md b/crates/rc-box/README.md index abd5a7c..7285df3 100644 --- a/crates/rc-box/README.md +++ b/crates/rc-box/README.md @@ -7,6 +7,10 @@ With the standard library types, you would use `get_mut` and have to handle the case where the value was shared. With the known unique versions, you have `DerefMut`, so it's as simple as mutating behind a `Box`. +Also note that `RcBox`, unlike `Rc`, implements `Send` and `Sync`. An `RcBox` can be sent to +another thread or stored in a shared collection, and then converted to an `Rc` for optimal +single-threaded use. This works for `Rc` as well, since `RefCell` is `Send`. + ## Related Crates - [`erasable`](https://lib.rs/crates/erasable): Erase pointers of their concrete type. diff --git a/crates/rc-box/src/lib.rs b/crates/rc-box/src/lib.rs index bfe4e1a..42c9481 100644 --- a/crates/rc-box/src/lib.rs +++ b/crates/rc-box/src/lib.rs @@ -8,6 +8,10 @@ //! With the standard library types, you would use `get_mut` and have to handle the impossible //! case where the value was shared. With the known unique versions, you have [`DerefMut`], //! so it's as simple as mutating behind a [`Box`]. +//! +//! Also note that `RcBox`, unlike `Rc`, implements `Send` and `Sync`. An `RcBox` can be sent to +//! another thread or stored in a shared collection, and then converted to an `Rc` for optimal +//! single-threaded use. This works for `Rc` as well, since `RefCell` is `Send`. #![warn(missing_docs, missing_debug_implementations)] #![no_std]