pub struct AnyResult { /* fields omitted */ }
Expand description
Like Any
, but instead of being a value of non-statically-determined type,
provides a result into which a specific type can be written.
use gazebo::any::AnyResult;
let mut res = AnyResult::new::<String>();
res.add(|| String::from("Hello"));
res.add(|| "goodbye");
res.add(|| 42);
assert_eq!(res.result::<String>(), Some(String::from("Hello")));
Create a new AnyResult
that can contain values of type T
.
Grab the value stored in an AnyResult
. Returns None
if no value
with the right type has been added, otherwise the first value that was
added. It is an error to call result
with a different type to that
which was used with new
.
Same as result
, but gets a reference.
Add a value with a given type to the AnyResult
. If this call is the first
where the type T
matches that used for new
then the function will be run.
impl<T> Any for T where
T: 'static + ?Sized,
Get an ARef
pointing at this type.
Try and get an ARef
pointing at this type. Returns an Err
if
the type Self
is a RefCell
which is already mutably borrowed. Read more
Return the underlying RefCell
if Self
is one, otherwise None
.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
impl<T, U> Into<U> for T where
U: From<T>,
Convert between two equal types.
Convert between references to two equal types.
Convert between mutable references to two equal types.
The type returned in the event of a conversion error.
The type returned in the event of a conversion error.