Skip to content

Commit

Permalink
docs: add note about thread-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Apr 25, 2024
1 parent 42f882e commit 6269950
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
![Docs](https://github.com/snormore/owned-ref-cell/actions/workflows/docs.yml/badge.svg)
[![codecov](https://codecov.io/gh/snormore/owned-ref-cell/graph/badge.svg?token=TGH857JV5B)](https://codecov.io/gh/snormore/owned-ref-cell)

The main class in this library, `OwnedRefCell<T>`, provides an interface similar to `RefCell<T>`, allowing both mutable and immutable borrows, tracked at runtime to ensure that there are no value races. `OwnedRefCell<T>` should be used when you need temporary mutable access to value inside a value structure that does not itself provide intrinsic mutable access. Similar to `RefCell`, this implementation is not thread-safe; it does not implement `Sync`. If you need thread-safe interior mutability, consider using `Mutex`, `RwLock`, or `Atomic` types.

## Features

- **Owned References**: Provides `OwnedRef` and `OwnedRefMut`, which manage the borrow state internally and allow for dynamic and flexible lifetimes.
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//! `OwnedRefCell<T>` should be used when you need temporary mutable access to value inside a value
//! structure that does not itself provide intrinsic mutable access.
//!
//! Similar to `RefCell`, this implementation is not thread-safe; it does not implement Sync. If you need
//! thread-safe interior mutability, consider using `Mutex`, `RwLock`, or `Atomic` types.
//!
//! # Differences from `RefCell`
//!
//! - `OwnedRefCell` provides `OwnedRef` and `OwnedRefMut`, which own their borrow status and thus
Expand All @@ -20,12 +23,6 @@
//! `OwnedRefCell` also offers methods (`try_borrow` and `try_borrow_mut`) that return `None` when
//! a borrow would violate the rules, allowing the caller to react without forcing a panic.
//!
//! # Safety
//!
//! Unlike `RefCell<T>`, `OwnedRefCell<T>` uses `Rc<T>` to track the borrowing state, and thus it is not
//! thread-safe. It is meant for use only in single-threaded scenarios. Attempting to use `OwnedRefCell<T>`
//! in a multithreaded context may lead to value races and is not supported.
//!
//! # Examples
//!
//! Basic usage:
Expand Down

0 comments on commit 6269950

Please sign in to comment.