2 unstable releases

0.1.0 Jun 2, 2022
0.0.1 Jun 2, 2022

#820 in Concurrency

Download history 4/week @ 2023-11-18 34/week @ 2023-11-25 120/week @ 2023-12-02 202/week @ 2023-12-09 50/week @ 2023-12-16 4/week @ 2023-12-23 23/week @ 2023-12-30 44/week @ 2024-01-06 62/week @ 2024-01-13 31/week @ 2024-01-20 17/week @ 2024-01-27 19/week @ 2024-02-03 21/week @ 2024-02-10 1/week @ 2024-02-17 11/week @ 2024-02-24 18/week @ 2024-03-02

53 downloads per month

MIT license

8KB
154 lines

syncell

Crates.io Docs.rs Build Status CodeCov.io

Just a Sync alternative to std::cell::RefCell. Useful when you have a value to share between tasks/closures, and you already know or guarantee that the access to the value is safe (for example, via choir task dependencies).

The cost of borrowing is a single atomic operation, and it's riguriously checked by both Loom and Miri.

Motivation

Rust already has tools for sharing values between threads, but it strikes me that they are all rather involved and complicated:

Shareable mutable containers exist to permit mutability in a controlled manner, even in the presence of aliasing. Both Cell<T> and RefCell<T> allow doing this in a single-threaded way. However, neither Cell<T> nor RefCell<T> are thread safe (they do not implement Sync). If you need to do aliasing and mutation between multiple threads it is possible to use Mutex<T>, RwLock<T> or atomic types.

This paragraph from std::cell documentation proposes to use lock-based primitives as an alternative in Sync world. But what if you just need sharing without locking, and still want safety? SynCell comes to help.

Dependencies

~0–29MB
~358K SLoC