Enum rustrt::local_data::KeyValue[src]
pub enum KeyValue<T> {
Key,
}Variants
Key |
Methods
impl<T: 'static> KeyValue<T>
fn replace(&'static self, data: Option<T>) -> Option<T>
Replaces a value in task local storage.
If this key is already present in TLS, then the previous value is replaced with the provided data, and then returned.
Failure
This function will fail if this key is present in TLS and currently on
loan with the get method.
Example
local_data_key!(foo: int) assert_eq!(foo.replace(Some(10)), None); assert_eq!(foo.replace(Some(4)), Some(10)); assert_eq!(foo.replace(None), Some(4));
fn get(&'static self) -> Option<Ref<T>>
Borrows a value from TLS.
If None is returned, then this key is not present in TLS. If Some is
returned, then the returned data is a smart pointer representing a new
loan on this TLS key. While on loan, this key cannot be altered via the
replace method.
Example
local_data_key!(key: int) assert!(key.get().is_none()); key.replace(Some(3)); assert_eq!(*key.get().unwrap(), 3);