[][src]Function canrun::goal::custom

pub fn custom<'a, D, F>(func: F) -> Goal<'a, D> where
    D: Domain<'a>,
    F: Fn(State<'a, D>) -> Option<State<'a, D>> + 'a, 

Create a goal that gives access to the underlying State struct.

Similar to lazy, the passed in callback is given access to the state so it can call the lower level State manipulation methods. This should approach should be used sparingly. Ideally most logic should be composable out of lower level primitive goals.

Because the State methods return an Option<[State]> the question mark operator ? can be used to allow chaining operations on the State.

Examples

use canrun::{Goal, custom, val, var};
use canrun::domains::example::I32;

let x = var();
let goal: Goal<I32> = custom(|state| {
    let y = var();
    state.unify(&val!(y), &val!(1))?
         .unify(&val!(x), &val!(y))
});
let result: Vec<_> = goal.query(x).collect();
assert_eq!(result, vec![1])