pub trait Reify {
type Reified;
// Required method
fn reify_in(&self, state: &ReadyState) -> Option<Self::Reified>;
}Expand description
Required Associated Types§
Required Methods§
Sourcefn reify_in(&self, state: &ReadyState) -> Option<Self::Reified>
fn reify_in(&self, state: &ReadyState) -> Option<Self::Reified>
Extract a reified Self from a compatible State. This trait is usually
used indirectly through the Query trait.
§Examples:
Simple values are typically copied or cloned (since the Value uses
an Rc internally).
use canrun::{Value, Reify, StateIterator, State};
State::new()
.into_states()
.filter_map(|s| s.ready())
.for_each(|state| {
let x = Value::new(1);
// This value is already resolved, so we simply get it back.
assert_eq!(x.reify_in(&state), Some(1));
});Structures containing additional Values should be recursively reified.
Reify is implemented for several tuple sizes to allow easy querying of
multiple Values.
State::new()
.into_states()
.filter_map(|s| s.ready())
.for_each(|state| {
let x = (Value::new(1), Value::new(2));
assert_eq!(x.reify_in(&state), Some((1, 2)));
});Returns None if the Value is unresolved. Note that this does not
currently do anything to help you if there are pending forks or
constraints that could affect resolution.
State::new()
.into_states()
.filter_map(|s| s.ready())
.for_each(|state| {
let x: Value<usize> = Value::var();
assert_eq!(x.reify_in(&state), None);
});Also returns None if Self is a structure containing any unresolved
Values.
State::new()
.into_states()
.filter_map(|s| s.ready())
.for_each(|state| {
let x: Value<i32> = Value::var();
let y = (x, Value::new(2));
assert_eq!(y.reify_in(&state), None);
});