libstd: Add a function to borrow a cell

This commit is contained in:
Patrick Walton 2012-08-16 19:36:49 -07:00
parent 0e3825d38c
commit 6d7b143036

View File

@ -39,6 +39,13 @@ impl<T> Cell<T> {
fn is_empty() -> bool {
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]