Use try_with for with implementation
This commit is contained in:
@@ -284,15 +284,8 @@ impl<T: 'static> LocalKey<T> {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn with<F, R>(&'static self, f: F) -> R
|
pub fn with<F, R>(&'static self, f: F) -> R
|
||||||
where F: FnOnce(&T) -> R {
|
where F: FnOnce(&T) -> R {
|
||||||
unsafe {
|
self.try_with(f).expect("cannot access a TLS value during or \
|
||||||
let slot = (self.inner)();
|
after it is destroyed")
|
||||||
let slot = slot.expect("cannot access a TLS value during or \
|
|
||||||
after it is destroyed");
|
|
||||||
f(match *slot.get() {
|
|
||||||
Some(ref inner) => inner,
|
|
||||||
None => self.init(slot),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn init(&self, slot: &UnsafeCell<Option<T>>) -> &T {
|
unsafe fn init(&self, slot: &UnsafeCell<Option<T>>) -> &T {
|
||||||
|
|||||||
Reference in New Issue
Block a user