pub struct Value { /* private fields */ }
Expand description
Wrapper over value of non-specified type.
Example
let v = Value::new(Box::new(42));
assert_eq!(v.is::<i32>(), true);
assert_eq!(v.is::<f32>(), false);
assert_eq!(v.get::<i32>(), Some(&42));
assert_eq!(v.into_cloned::<i32>(), Some(42));
assert_eq!(v.into_cloned::<f32>(), None);
assert_eq!(v.unwrap::<i32>(), &42);
assert_eq!(v.consume::<i32>(), 42);
Implementations§
source§impl Value
impl Value
sourcepub fn get<T: 'static>(&self) -> Option<&T>
pub fn get<T: 'static>(&self) -> Option<&T>
Gets reference to value of given type or None
if its not of that type.
sourcepub fn get_mut<T: 'static>(&mut self) -> Option<&mut T>
pub fn get_mut<T: 'static>(&mut self) -> Option<&mut T>
Gets mutable reference to value of given type or None
if its not of that type.
sourcepub fn into_cloned<T>(&self) -> Option<T>where
T: Clone + 'static,
pub fn into_cloned<T>(&self) -> Option<T>where
T: Clone + 'static,
Gets cloned value of given type or None
if its not of that type.
sourcepub fn unwrap<T: 'static>(&self) -> &T
pub fn unwrap<T: 'static>(&self) -> &T
Gets reference to value of given type or panics if its not of that type.
Panics
- when trying to use target type other than that of inner value.
sourcepub fn unwrap_mut<T: 'static>(&mut self) -> &mut T
pub fn unwrap_mut<T: 'static>(&mut self) -> &mut T
Gets mutable reference to value of given type or panics if its not of that type.
Panics
- when trying to use target type other than that of inner value.