https://github.com/qnighy/option-cell
OptionCell: OnceCell but derivable from Option
https://github.com/qnighy/option-cell
rust rust-patterns unification unification-algorithm
Last synced: 11 days ago
JSON representation
OptionCell: OnceCell but derivable from Option
- Host: GitHub
- URL: https://github.com/qnighy/option-cell
- Owner: qnighy
- License: other
- Created: 2023-09-10T06:05:37.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-10T06:12:41.000Z (over 1 year ago)
- Last Synced: 2024-10-06T02:42:38.901Z (7 months ago)
- Topics: rust, rust-patterns, unification, unification-algorithm
- Language: Rust
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-Apache-2.0
Awesome Lists containing this project
README
## OptionCell: OnceCell but derivable from Option
This library provides an equivalent of [OnceCell](https://doc.rust-lang.org/stable/std/cell/struct.OnceCell.html), but it guarantees layout compatibility with `Option`, providing additional transmute helpers.
## Known use-cases
- Implementing the [unification algorithm](https://en.wikipedia.org/wiki/Unification_(computer_science)) without exposing the interior mutability to the user or unnecessarily cloning the value.
## Usage
```txt
cargo add option-cell
``````rust
use option_cell::OptionCell;let mut options = vec![None, None];
let cells = OptionCell::from_mut_slice(&mut options);
cells[0].set(1).unwrap();
```## Development
Check with MIRI:
```
cargo +nightly miri test
```