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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Get an iterator of all valid, resolved states that can be derived. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.