Module take_mut::scoped [−][src]
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
Hole | A |
Scope | Represents a scope within which, it is possible to take a |
Functions
scope | Main function to create a |