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<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]
This commit is contained in:
@@ -289,12 +289,10 @@ macro_rules! println(
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::local_data;
|
||||
///
|
||||
/// local_data_key!(my_integer: int)
|
||||
///
|
||||
/// local_data::set(my_integer, 2);
|
||||
/// local_data::get(my_integer, |val| println!("{}", val.map(|i| *i)));
|
||||
/// my_integer.replace(Some(2));
|
||||
/// println!("{}", my_integer.get().map(|a| *a));
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! local_data_key(
|
||||
|
||||
Reference in New Issue
Block a user