libstd: Add a function to borrow a cell
This commit is contained in:
parent
0e3825d38c
commit
6d7b143036
1 changed files with 8 additions and 1 deletions
|
@ -39,6 +39,13 @@ impl<T> Cell<T> {
|
||||||
fn is_empty() -> bool {
|
fn is_empty() -> bool {
|
||||||
self.value.is_none()
|
self.value.is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calls a closure with a reference to the value.
|
||||||
|
fn with_ref(f: fn(v: &T)) {
|
||||||
|
let val = move self.take();
|
||||||
|
f(&val);
|
||||||
|
self.put_back(move val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue