option-cell

Crates.iooption-cell
lib.rsoption-cell
version0.1.0
sourcesrc
created_at2023-09-10 06:09:43.707531
updated_at2023-09-10 06:09:43.707531
descriptionOptionCell: OnceCell but derivable from Option
homepage
repositoryhttps://github.com/qnighy/option-cell
max_upload_size
id968621
size12,108
Masaki Hara (qnighy)

documentation

README

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();

Development

Check with MIRI:

cargo +nightly miri test
Commit count: 4

cargo fmt