about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-05-08 01:26:39 -0700
committerbors <bors@rust-lang.org>2014-05-08 01:26:39 -0700
commitb9ff86e27f53af10de0302033b659061d659b69b (patch)
tree92749609d3a8645b7ad37a47fd20c8e60df77299 /src/libstd/rt
parentc39b1cb1bed78d989b1011f54f6febb7e9e46d94 (diff)
parentab92ea526d455b402efbccc7160c8aec0237c88f (diff)
downloadrust-b9ff86e27f53af10de0302033b659061d659b69b.tar.gz
rust-b9ff86e27f53af10de0302033b659061d659b69b.zip
auto merge of #13835 : alexcrichton/rust/localdata, r=brson
This commit brings the local_data api up to modern rust standards with a few key
improvements:

* All functionality is now exposed as a method on the keys themselves. Instead
  of importing std::local_data, you now use "key.set()" and "key.get()".

* All closures have been removed in favor of RAII functionality. This means that
  get() and get_mut() no long require closures, but rather return
  Option<SmartPointer> where the smart pointer takes care of relinquishing the
  borrow and also implements the necessary Deref traits

* The modify() function was removed to cut the local_data interface down to its
  bare essentials (similarly to how RefCell removed set/get).

[breaking-change]
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/task.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs
index 8924ed7cfd2..77bcb7b9904 100644
--- a/src/libstd/rt/task.rs
+++ b/src/libstd/rt/task.rs
@@ -420,13 +420,12 @@ mod test {
 
     #[test]
     fn tls() {
-        use local_data;
         local_data_key!(key: @~str)
-        local_data::set(key, @"data".to_owned());
-        assert!(*local_data::get(key, |k| k.map(|k| *k)).unwrap() == "data".to_owned());
+        key.replace(Some(@"data".to_owned()));
+        assert_eq!(key.get().unwrap().as_slice(), "data");
         local_data_key!(key2: @~str)
-        local_data::set(key2, @"data".to_owned());
-        assert!(*local_data::get(key2, |k| k.map(|k| *k)).unwrap() == "data".to_owned());
+        key2.replace(Some(@"data".to_owned()));
+        assert_eq!(key2.get().unwrap().as_slice(), "data");
     }
 
     #[test]