Struct deferred::value::Value

source ·
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§

Returns new value.

Arguments
  • value - boxed value of any type.

Tells if value is type of given type.

Gets reference to value of given type or None if its not of that type.

Gets mutable reference to value of given type or None if its not of that type.

Gets cloned value of given type or None if its not of that type.

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.

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.

Consumes value of given type and returns it or panics if its not of that type.

Panics
  • when trying to use target type other than that of inner value.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.