Struct canrun::goals::Goal [−][src]
pub struct Goal<'a, D: Domain<'a>>(_);
Expand description
A container of one of many possible types of goals.
Values of this type are typically constructed with one of the many
constructor functions and
macros. These high level methods provide automatic
value wrapping through IntoVal
and other niceties.
Implementations
Create a Goal that always succeeds.
Example
use canrun::{Goal, all, unify, var}; use canrun::example::I32; let x = var(); let goal: Goal<I32> = all![unify(x, 1), Goal::succeed()]; let result: Vec<_> = goal.query(x).collect(); assert_eq!(result, vec![1])
Create a Goal that always fails.
Example
use canrun::{Goal, all, unify, var}; use canrun::example::I32; let x = var(); let goal: Goal<I32> = all![unify(x, 1), Goal::fail()]; let result: Vec<_> = goal.query(x).collect(); assert_eq!(result, vec![])
Create a goal containing a Fork
object.
Create a goal containing a Constraint
object.
Create a Goal that only succeeds if all sub-goals succeed.
This constructor takes anything that implements
IntoIterator
for a compatible goal type.
See the all!
macro for a slightly higher level
interface.
Example
use canrun::{Goal, all, unify, var}; use canrun::example::I32; let x = var(); let y = var(); let goal: Goal<I32> = Goal::all(vec![unify(y, x), unify(1, x), unify(y, 1)]); let result: Vec<_> = goal.query((x, y)).collect(); assert_eq!(result, vec![(1, 1)])
Create a Goal that yields a state for every successful sub-goal.
This constructor takes anything that implements
IntoIterator
for a compatible goal type.
See the any!
macro for a slightly higher level
interface.
Example
use canrun::{Goal, any, unify, var}; use canrun::example::I32; let x = var(); let goal: Goal<I32> = Goal::any(vec![unify(x, 1), unify(x, 2), unify(x, 3)]); let result: Vec<_> = goal.query(x).collect(); assert_eq!(result, vec![1, 2, 3])
Apply the Goal to an existing state.
This will update the state, but not iterate through the possible
resolved states. For this you still need to use the
.iter_resolved()
interface or
.query()
.
Example
use canrun::{Goal, State, unify, var}; use canrun::example::I32; let x = var(); let state = State::new(); let goal: Goal<I32> = unify(x, 1); let state: Option<State<I32>> = goal.apply(state);
Use the query interface to get an iterator of result values.
This is a shorthand for creating a new state, applying the goal and
calling .query()
on the resulting state.
Example:
use canrun::{Goal, unify, var}; use canrun::example::I32; let x = var(); let goal: Goal<I32> = unify(x, 1); let result: Vec<_> = goal.query(x).collect(); assert_eq!(result, vec![1])
Trait Implementations
Auto Trait Implementations
impl<'a, D> !RefUnwindSafe for Goal<'a, D>
impl<'a, D> !UnwindSafe for Goal<'a, D>
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self