INNER CODE UNIT · Rust
get_or_insert_with
fishfolk/bones · framework_crates/bones_asset/src/lib.rs:193
pub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T {
if let Maybe::Unset = self {
*self = Maybe::Set(f());
}
match self {
Maybe::Set(ref mut v) => v,
Maybe::Unset => unreachable!(),
}
}
/// Takes the value out of the option, leaving an `Unset` in its place.
#[inline]
pub fn take(&mut self) -> Maybe<T> {
std::mem::replace(self, Maybe::Unset)
}
/// Replaces the actual value in the option by the value given in parameter, returning the old value if present.
#[inline]