Crate option_cell
source ·Expand description
OptionCell: OnceCell but derivable from Option
This library provides an equivalent of OnceCell, but it guarantees layout compatibility with Option<T>
, providing additional transmute helpers.
Known use-cases
- Implementing the unification algorithm without exposing the interior mutability to the user or unnecessarily cloning the value.
Usage
cargo add option-cell
use option_cell::OptionCell;
let mut options = vec![None, None];
let cells = OptionCell::from_mut_slice(&mut options);
cells[0].set(1).unwrap();
Structs
- An equivalent of std::cell::OnceCell or once_cell::unsync::OnceCell with an additional transmute helper. To guarantee the helper’s safety, it is defined as a different type from the original OnceCell.