Trait canrun::value::ReifyIn[][src]

pub trait ReifyIn<'a, D>: Sized {
    type Reified;
    fn reify_in(&self, state: &ResolvedState<D>) -> Option<Self::Reified>;
}
Expand description

Extract a fully resolved T from a Val<T>.

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

Associated Types

The “concrete” type that Self reifies to.

Required methods

Extract a reified Self from a compatible ResolvedState. This trait is usually used indirectly through the Query trait.

Examples:

Simple values are typically copied or cloned (since the Val stores in an Rc internally).

use canrun::{Val, val, var, ReifyIn, IterResolved, State, ResolvedState};
use canrun::example::{I32, TupleI32};
State::new()
    .iter_resolved()
    .for_each(|state: ResolvedState<I32>| {
        let x = val!(1);
        assert_eq!(x.reify_in(&state), Some(1));
    });

Structures containing additional Vals should be recursively reified.

State::new()
    .iter_resolved()
    .for_each(|state: ResolvedState<TupleI32>| {
        let x = (val!(1), val!(2));
        assert_eq!(x.reify_in(&state), Some((1, 2)));
    });

Returns None if the Val is unresolved.

State::new()
    .iter_resolved()
    .for_each(|state: ResolvedState<I32>| {
        let x: Val<i32> = val!(var());
        assert_eq!(x.reify_in(&state), None);
    });

Also returns None if Self is a structure containing any unresolved Vals.

State::new()
    .iter_resolved()
    .for_each(|state: ResolvedState<TupleI32>| {
        let x: Val<i32> = val!(var());
        let y = (x, val!(2));
        assert_eq!(y.reify_in(&state), None);
    });

Implementations on Foreign Types

Implementors