Trait WritableOptionExt

Source
pub trait WritableOptionExt<T: 'static>: Writable<Target = Option<T>> {
    // Provided methods
    fn get_or_insert(&mut self, default: T) -> WritableRef<'_, Self, T> { ... }
    fn get_or_insert_with(
        &mut self,
        default: impl FnOnce() -> T,
    ) -> WritableRef<'_, Self, T> { ... }
    fn as_mut(&mut self) -> Option<WritableRef<'_, Self, T>> { ... }
}
Expand description

An extension trait for Writable<Option<T>>` that provides some convenience methods.

Provided Methods§

Source

fn get_or_insert(&mut self, default: T) -> WritableRef<'_, Self, T>

Gets the value out of the Option, or inserts the given value if the Option is empty.

Source

fn get_or_insert_with( &mut self, default: impl FnOnce() -> T, ) -> WritableRef<'_, Self, T>

Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.

Source

fn as_mut(&mut self) -> Option<WritableRef<'_, Self, T>>

Attempts to write the inner value of the Option.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, W> WritableOptionExt<T> for W
where T: 'static, W: Writable<Target = Option<T>>,