Enum canrun::core::constraints::TwoOfThree
source · 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 Value
s or return an Err(LVarList)
in a Constraint
.
Variants§
AB(Rc<A>, Rc<B>, Value<C>)
Returned when the first and second Value
s are successfully resolved.
BC(Value<A>, Rc<B>, Rc<C>)
Returned when the second and third Value
s are successfully resolved.
AC(Rc<A>, Value<B>, Rc<C>)
Returned when the first and third Value
s are successfully resolved.
Implementations§
source§impl<A: Unify, B: Unify, C: Unify> TwoOfThree<A, B, C>
impl<A: Unify, B: Unify, C: Unify> TwoOfThree<A, B, C>
sourcepub fn resolve(
a: &Value<A>,
b: &Value<B>,
c: &Value<C>,
state: &State
) -> Result<TwoOfThree<A, B, C>, LVarList>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more