pub struct NonOption<T> { /* private fields */ }
Expand description
An Option that is not really optional (but is still kinda). Start by creating the object by calling invalid (probably as a field in a struct constructor) and setting a value by calling “set” with a parameter as soon as possible. Attempting to use an invalid NonOption will cause a panic, so make absolutely sure you’ve set it with a value before calling “get_ref”, “get_mut” etc.
NonOptions are useful when you have objects that refernce each other but cannot have these references set during initalisation (becuse one of the objects does not yet exist).
Implementations§
Source§impl<T> NonOption<T>
impl<T> NonOption<T>
pub fn new_rfc(value: T) -> RefCell<Self>
pub fn invalid_rfc() -> RefCell<Self>
pub fn get_ref(&self) -> &T
pub fn get_mut(&mut self) -> &mut T
pub fn try_get_ref(&self) -> Option<&T>
pub fn try_get_mut(&mut self) -> Option<&mut T>
pub fn is_valid(&self) -> bool
pub fn is_invalid(&self) -> bool
pub fn unwrap_or(self, default: T) -> T
pub fn expect(self) -> T
pub fn set(&mut self, value: T)
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for NonOption<T>where
T: Freeze,
impl<T> RefUnwindSafe for NonOption<T>where
T: RefUnwindSafe,
impl<T> Send for NonOption<T>where
T: Send,
impl<T> Sync for NonOption<T>where
T: Sync,
impl<T> Unpin for NonOption<T>where
T: Unpin,
impl<T> UnwindSafe for NonOption<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more