Trait canrun::goals::Goal

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

Types implementing Goal represent declarative, lazily applied state updates.

Required Methods§

source

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]);

Implementations on Foreign Types§

source§

impl Goal for Rc<dyn Goal>

source§

fn apply(&self, state: State) -> Option<State>

Implementors§

source§

impl Goal for Not

source§

impl Goal for All

source§

impl Goal for Any

source§

impl Goal for Both

source§

impl Goal for Custom

source§

impl Goal for Either

source§

impl Goal for Fail

source§

impl Goal for Lazy

source§

impl Goal for Succeed

source§

impl<A: Unify> Goal for Project1<A>

source§

impl<A: Unify, B: Unify> Goal for Assert2<A, B>

source§

impl<A: Unify, B: Unify> Goal for Map1<A, B>

source§

impl<A: Unify, B: Unify> Goal for Project2<A, B>

source§

impl<A: Unify, B: Unify, C: Unify> Goal for Map2<A, B, C>

source§

impl<T: Unify> Goal for Get<T>

source§

impl<T: Unify> Goal for Member<T>

source§

impl<T: Unify> Goal for Slice<T>

source§

impl<T: Unify> Goal for Subset<T>

source§

impl<T: Unify> Goal for Assert1<T>

source§

impl<T: Unify> Goal for Unify<T>