3个版本
| 0.1.2 | 2020年2月28日 | 
|---|---|
| 0.1.1 | 2020年2月28日 | 
| 0.1.0 | 2020年2月28日 | 
#2775 in Rust模式
6KB
Take Cell Option
用于从option的cell中取出值而不进行克隆的实用工具。
用法
将 take_cell_option = "0.1" 添加到依赖项中。
示例
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:
用于从Cell<Option<T>>中取出值而不进行克隆。
取出后,cell将包含None。
示例
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());