3 releases
0.1.2 | Feb 28, 2020 |
---|---|
0.1.1 | Feb 28, 2020 |
0.1.0 | Feb 28, 2020 |
#2905 in Rust patterns
6KB
Take Cell Option
Utility for taking the value from a cell of a option without cloning.
Usage
Add take-cell-option = "0.1"
to your dependencies.
Example
use take_cell_option::take;
use core::cell::Cell;
let cell = Cell::new(Some(Box::new(10)));
let v = take(&cell);
assert_eq!(*v.unwrap(), 10);
assert!(cell.into_inner().is_none());
lib.rs
:
Utility for taking the value from a Cell<Option<T>>
without cloning.
After taking, the cell will have a None
.
Example
use take_cell_option::take;
use core::cell::Cell;
let cell = Cell::new(Some(Box::new(10)));
let v = take(&cell);
assert_eq!(*v.unwrap(), 10);
assert!(cell.into_inner().is_none());