Trait canrun::core::Reify

source ·
pub trait Reify {
    type Reified;

    fn reify_in(&self, state: &State) -> Option<Self::Reified>;
}
Expand description

Extract a fully resolved T from a Value<T> associated with a State.

Used by Query to ensure that result values are fully and recursively resolved.

Required Associated Types§

The “concrete” type that Self reifies to.

Required Methods§

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()
    .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()
    .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()
    .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()
    .for_each(|state| {
        let x: Value<i32> = Value::var();
        let y = (x, Value::new(2));
        assert_eq!(y.reify_in(&state), None);
    });

Implementations on Foreign Types§

Implementors§