Enum rustrt::local_data::KeyValueExperimental
[-]
[+]
[src]
pub enum KeyValue<T> {
KeyValueKey,
}Variants
KeyValueKey |
Methods
impl<T: 'static> KeyValue<T>
fn replace(&'static self, data: Option<T>) -> Option<T>
Replaces a value in task local data.
If this key is already present in TLD, then the previous value is replaced with the provided data, and then returned.
Panics
This function will panic if the key is present in TLD and currently on
loan with the get method.
It will also panic if there is no local task (because the current thread is not owned by the runtime).
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 TLD.
If None is returned, then this key is not present in TLD. If Some
is returned, then the returned data is a smart pointer representing a
new loan on this TLD 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);