From ab92ea526d455b402efbccc7160c8aec0237c88f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 28 Apr 2014 20:36:08 -0700 Subject: std: Modernize the local_data api This commit brings the local_data api up to modern rust standards with a few key improvements: * The `pop` and `set` methods have been combined into one method, `replace` * The `get_mut` method has been removed. All interior mutability should be done through `RefCell`. * All functionality is now exposed as a method on the keys themselves. Instead of importing std::local_data, you now use "key.replace()" 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 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] --- src/libstd/rt/task.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/libstd/rt') diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 5b29de5a8c1..68d8c446cf9 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -414,13 +414,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] -- cgit 1.4.1-3-g733a5