diff options
Diffstat (limited to 'src/libstd/thread_local')
| -rw-r--r-- | src/libstd/thread_local/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/thread_local/scoped.rs | 8 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 029b8bf1138..b85b6eccb77 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -218,7 +218,9 @@ impl<T: 'static> Key<T> { /// This function will `panic!()` if the key currently has its /// destructor running, and it **may** panic if the destructor has /// previously been run for this thread. - pub fn with<R>(&'static self, f: |&T| -> R) -> R { + pub fn with<R, F>(&'static self, f: F) -> R where + F: FnOnce(&T) -> R, + { let slot = (self.inner)(); unsafe { let slot = slot.get().expect("cannot access a TLS value during or \ diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index 11d539c4f9f..ee742ab8375 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -135,7 +135,9 @@ impl<T> Key<T> { /// assert_eq!(val, 100); /// }); /// ``` - pub fn set<R>(&'static self, t: &T, cb: || -> R) -> R { + pub fn set<R, F>(&'static self, t: &T, cb: F) -> R where + F: FnOnce() -> R, + { struct Reset<'a, T: 'a> { key: &'a KeyInner<T>, val: *mut T, @@ -175,7 +177,9 @@ impl<T> Key<T> { /// // work with `slot` /// }); /// ``` - pub fn with<R>(&'static self, cb: |&T| -> R) -> R { + pub fn with<R, F>(&'static self, cb: F) -> R where + F: FnOnce(&T) -> R + { unsafe { let ptr = self.inner.get(); assert!(!ptr.is_null(), "cannot access a scoped thread local \ |
