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 T
which must be filled before the end of the Scope
with lifetime 'c
and recovery closure F
.
Represents a scope within which, it is possible to take a T
from a &mut T
as long as the &mut T
outlives the scope.
Functions
Main function to create a Scope
.