Expand description
This module provides a scoped API, allowing for taking an arbitrary number of &mut T into T within one closure.
The references are all required to outlive the closure.
Example
use take_mut::scoped;
struct Foo;
let mut foo = Foo; // Must outlive scope
scoped::scope(|scope| {
let (t, hole) = scope.take(&mut foo);
drop(t);
hole.fill(Foo); // If not called before the closure ends, causes an abort.
});Invalid Example (does not compile)
ⓘ
use take_mut::scoped;
struct Foo;
scoped::scope(|scope| {
let mut foo = Foo; // Invalid because foo must come from outside the scope.
let (t, hole) = scope.take(&mut foo);
drop(t);
hole.fill(Foo);
});Scope also offers take_or_recover, which takes a function to call in the event the hole isn’t filled.
Structs
- A
Hole<'c, 'm, T, F>represents an unfilled&'m mut Twhich must be filled before the end of theScopewith lifetime'cand recovery closureF. - Represents a scope within which, it is possible to take a
Tfrom a&mut Tas long as the&mut Toutlives the scope.
Functions
- Main function to create a
Scope.