diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2014-12-07 14:15:25 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2014-12-13 17:03:47 -0500 |
| commit | cdbb3ca9b776b066e2c93acfb60da8537d2b1c9b (patch) | |
| tree | 18a305205c51df4501a5e5e73c4b275242fb5a25 /src/libstd/thread_local | |
| parent | be53d619f874cbe8e4d87f900060561d16405d53 (diff) | |
| download | rust-cdbb3ca9b776b066e2c93acfb60da8537d2b1c9b.tar.gz rust-cdbb3ca9b776b066e2c93acfb60da8537d2b1c9b.zip | |
libstd: use unboxed closures
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 \ |
