take_mut
Rust API reference for the module take_mut.
Public API
Function: take
Canonical path: take_mut::take
Declared in: src/lib.rs
Signature
pub fn take<T, F>(mut_ref: &mut T, closure: F)
where F: FnOnce(T) -> T {}
Summary
Allows use of a value pointed to by `&mut T` as though it was owned, as long as a `T` is made available afterwards.
Behavior
The closure must return a valid T.
Parameters
- mut_ref: A mutable reference to a value of type T that is temporarily moved out of during the execution of the closure.
- closure: A closure that receives the owned value of type T and must return a valid T to replace it.
Function: take_or_recover
Canonical path: take_mut::take_or_recover
Declared in: src/lib.rs
Signature
pub fn take_or_recover<T, F, R>(mut_ref: &mut T, recover: R, closure: F)
where F: FnOnce(T) -> T, R: FnOnce() -> T {}
Summary
Allows use of a value pointed to by `&mut T` as though it was owned, as long as a `T` is made available afterwards.
Behavior
The closure must return a valid T.
Parameters
- mut_ref: A mutable reference to a value of type T that will be temporarily moved out of.
- recover: A closure that returns a replacement value of type T if the primary closure panics.
- closure: A closure that takes the owned value of type T and returns a new value of type T to be placed back into the mutable reference.