OwnedRefCell
OwnedRefCell is a custom implementation of Rust's RefCell that allows for a different borrowing mechanism. Unlike RefCell which grants references tied to the lifetimes of borrow scopes, OwnedRefCell returns special owned references. These references maintain their borrowed state until they are explicitly dropped, offering more flexibility in managing lifetimes in complex or dynamic application structures.
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
OwnedRefandOwnedRefMut, which manage the borrow state internally and allow for dynamic and flexible lifetimes. - Safe Borrowing: Ensures safe borrowing at runtime, preventing data races and enabling mutable or immutable access as needed.
- Easy Integration: Designed to be a drop-in replacement for scenarios where
RefCell's lifetime management is too restrictive.
Getting Started
Ensure you have Rust installed on your machine. If not, you can install Rust by following the instructions on the official Rust site.
Installation
Add OwnedRefCell to your Rust project by including it in your Cargo.toml dependencies:
[]
= { = "https://github.com/snormore/owned_ref_cell.git" }
Usage
Here is a simple example of how to use OwnedRefCell:
use OwnedRefCell;
use HashMap;
Documentation
Find more detailed documentation here, or run the following command to generate docs and view them in your browser:
Contributing
Contributions are welcome! Please feel free to submit pull requests, create issues for bugs and feature requests, and contribute to improving the documentation.
Support
If you encounter any issues or require assistance, please file an issue on the GitHub repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.