pub enum TwoOfThree<A: Unify, B: Unify, C: Unify> {
    AB(Rc<A>, Rc<B>, Value<C>),
    BC(Value<A>, Rc<B>, Rc<C>),
    AC(Rc<A>, Value<B>, Rc<C>),
}
Expand description

Resolve two out of three Values or return an Err(LVarList) in a Constraint.

Variants§

§

AB(Rc<A>, Rc<B>, Value<C>)

Returned when the first and second Values are successfully resolved.

§

BC(Value<A>, Rc<B>, Rc<C>)

Returned when the second and third Values are successfully resolved.

§

AC(Rc<A>, Value<B>, Rc<C>)

Returned when the first and third Values are successfully resolved.

Implementations§

source§

impl<A: Unify, B: Unify, C: Unify> TwoOfThree<A, B, C>

source

pub fn resolve( a: &Value<A>, b: &Value<B>, c: &Value<C>, state: &State ) -> Result<TwoOfThree<A, B, C>, LVarList>

Attempt to resolve a TwoOfThree enum from a State.

Examples: If no vars are resolved, you’ll get back an Err<LVarList> suitable for returning from a Constraint::attempt().

use canrun::{State, Value, LVarList};
use canrun::constraints::TwoOfThree;

let state = State::new();
let a: Value<usize> = Value::var();
let b: Value<usize> = Value::var();
let c: Value<usize> = Value::var();
let resolved = TwoOfThree::resolve(&a, &b, &c, &state);
assert!(resolved.is_err());

If two of the vars is able to be resolved from the State, the return value will be an Ok containing the unresolved Value::Var and the resolved value in an Rc.


let state = state.unify(&a, &Value::new(1)).unwrap();
let state = state.unify(&b, &Value::new(2)).unwrap();
let resolved = TwoOfThree::resolve(&a, &b, &c, &state);
match resolved {
Ok(TwoOfThree::AB(a, b, var)) => {
assert_eq!(*a, 1);
assert_eq!(*b, 2);
},
}
Errors

Returns a list with any [LVar]s that are still unresolved.

Auto Trait Implementations§

§

impl<A, B, C> RefUnwindSafe for TwoOfThree<A, B, C>where A: RefUnwindSafe, B: RefUnwindSafe, C: RefUnwindSafe,

§

impl<A, B, C> !Send for TwoOfThree<A, B, C>

§

impl<A, B, C> !Sync for TwoOfThree<A, B, C>

§

impl<A, B, C> Unpin for TwoOfThree<A, B, C>where A: Unpin, B: Unpin, C: Unpin,

§

impl<A, B, C> UnwindSafe for TwoOfThree<A, B, C>where A: UnwindSafe + RefUnwindSafe, B: UnwindSafe + RefUnwindSafe, C: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.