[][src]Struct canrun::goals::Goal

pub struct Goal<'a, D: Domain<'a>>(_);

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

impl<'a, D: Domain<'a> + 'a> Goal<'a, D>[src]

pub fn succeed() -> Self[src]

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

pub fn fail() -> Self[src]

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![])

pub fn fork<F: Fork<'a, D> + 'a>(fork: F) -> Self[src]

Create a goal containing a Fork object.

pub fn constraint<F: Constraint<'a, D> + 'a>(constraint: F) -> Self[src]

Create a goal containing a Constraint object.

pub fn all<I: IntoIterator<Item = Goal<'a, D>>>(goals: I) -> Self[src]

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

pub fn any<I: IntoIterator<Item = Goal<'a, D>>>(goals: I) -> Self[src]

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

pub fn apply(self, state: State<'a, D>) -> Option<State<'a, D>>[src]

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

pub fn query<Q>(self, query: Q) -> Box<dyn Iterator<Item = Q::Reified> + 'a> where
    Q: ReifyIn<'a, D> + 'a, 
[src]

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

impl<'a, D: Clone + Domain<'a>> Clone for Goal<'a, D>[src]

impl<'a, D: Debug + Domain<'a>> Debug for Goal<'a, D>[src]

impl<'a, D: Domain<'a> + 'a> IterResolved<'a, D> for Goal<'a, D>[src]

Auto Trait Implementations

impl<'a, D> !RefUnwindSafe for Goal<'a, D>

impl<'a, D> !Send for Goal<'a, D>

impl<'a, D> !Sync for Goal<'a, D>

impl<'a, D> Unpin for Goal<'a, D> where
    <D as Domain<'a>>::Value: Unpin

impl<'a, D> !UnwindSafe for Goal<'a, D>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,