all: add (Clone)Cell::is_some and is_none
This commit is contained in:
parent
7a67784502
commit
54d93f84da
32 changed files with 98 additions and 62 deletions
16
src/utils/cell_ext.rs
Normal file
16
src/utils/cell_ext.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use std::cell::Cell;
|
||||
|
||||
pub trait CellExt {
|
||||
fn is_some(&self) -> bool;
|
||||
fn is_none(&self) -> bool;
|
||||
}
|
||||
|
||||
impl<T: Copy> CellExt for Cell<Option<T>> {
|
||||
fn is_some(&self) -> bool {
|
||||
self.get().is_some()
|
||||
}
|
||||
|
||||
fn is_none(&self) -> bool {
|
||||
self.get().is_none()
|
||||
}
|
||||
}
|
||||
|
|
@ -59,6 +59,19 @@ impl<T> CloneCell<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> CloneCell<Option<T>> {
|
||||
#[inline(always)]
|
||||
pub fn is_some(&self) -> bool {
|
||||
unsafe { self.data.get().deref().is_some() }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
pub fn is_none(&self) -> bool {
|
||||
unsafe { self.data.get().deref().is_none() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default> Default for CloneCell<T> {
|
||||
fn default() -> Self {
|
||||
Self::new(Default::default())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue