1
0
Fork 0
forked from wry/wry
wry/utils/src/opt.rs

27 lines
457 B
Rust

use {crate::clonecell::CloneCell, std::rc::Rc};
pub struct Opt<T> {
t: CloneCell<Option<Rc<T>>>,
}
impl<T> Default for Opt<T> {
fn default() -> Self {
Self {
t: Default::default(),
}
}
}
impl<T> Opt<T> {
pub fn set(&self, t: Option<Rc<T>>) {
self.t.set(t);
}
pub fn get(&self) -> Option<Rc<T>> {
self.t.get()
}
pub fn is_none(&self) -> bool {
self.t.is_none()
}
}