Trait canrun::goals::Goal

source ·
pub trait Goal: Debug + 'static {
    fn apply(&self, state: State) -> Option<State>;
Expand description

Types implementing Goal represent declarative, lazily applied state updates.

Required Methods§

Apply the Goal to a state, returning Some if the state is still valid, or None.

use canrun::{State, Query, Value};
use canrun::goals::Goal;

struct Is1 {value: Value<usize>}

impl Goal for Is1 {
    fn apply(&self, state: State) -> Option<State> {
        state.unify(&Value::new(1), &self.value)

let x = Value::var();
let goal = Is1 {value: x.clone()};
let results: Vec<_> = goal.query(x).collect();
assert_eq!(results, vec![1]);

Implementations on Foreign Types§