Skip to main content

get_or_insert_with

Function get_or_insert_with 

Source
pub fn get_or_insert_with<T: Storable, B: Backend>(
    mem: &mut impl Mutex<T = ObjShelf<B>>,
    name: &str,
    f: impl FnOnce() -> T,
) -> Result<Option<Handle<T>>, Error<B::Error>>
Expand description

Handle to the object name. If there is no object with this name (as on the first boot), inserts the value returned by f first; f only runs in that case, and it fails as insert does.

T must be the type the object was inserted with, as for get.