Expand description
Types implementing Goal
represent declarative, lazily applied state updates.
Required Methods§
sourcefn apply(&self, state: State) -> Option<State>
fn apply(&self, state: State) -> Option<State>
Apply the Goal
to a state, returning Some
if the state is still valid, or None
.
Example:
use canrun::{State, Query, Value};
use canrun::goals::Goal;
#[derive(Debug)]
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]);