in midst of refactor
This commit is contained in:
11
orchidlang/src/utils/take_with_output.rs
Normal file
11
orchidlang/src/utils/take_with_output.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
//! Map over a `&mut` and return an additional value
|
||||
|
||||
/// A variation on [take_mut::take] that allows the callback to return a value
|
||||
pub fn take_with_output<T, U>(src: &mut T, cb: impl FnOnce(T) -> (T, U)) -> U {
|
||||
take_mut::scoped::scope(|scope| {
|
||||
let (old, hole) = scope.take(src);
|
||||
let (new, out) = cb(old);
|
||||
hole.fill(new);
|
||||
out
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user