diff --git a/README.md b/README.md index cd6a230..3fe55e2 100644 --- a/README.md +++ b/README.md @@ -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`, provides an interface similar to `RefCell`, allowing both mutable and immutable borrows, tracked at runtime to ensure that there are no value races. `OwnedRefCell` 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. diff --git a/src/lib.rs b/src/lib.rs index fcf53df..53eb742 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,9 @@ //! `OwnedRefCell` 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 @@ -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`, `OwnedRefCell` uses `Rc` 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` -//! in a multithreaded context may lead to value races and is not supported. -//! //! # Examples //! //! Basic usage: