Enum canrun::core::constraints::OneOfTwo
source · pub enum OneOfTwo<A: Unify, B: Unify> {
A(Rc<A>, Value<B>),
B(Value<A>, Rc<B>),
}
Expand description
Resolve one out of two Value
s or return an Err(LVarList)
in
a Constraint
.
Variants§
A(Rc<A>, Value<B>)
Returned when the first Value
is successfully resolved.
B(Value<A>, Rc<B>)
Returned when the second Value
is successfully resolved.
Implementations§
source§impl<A: Unify, B: Unify> OneOfTwo<A, B>
impl<A: Unify, B: Unify> OneOfTwo<A, B>
sourcepub fn resolve(
a: &Value<A>,
b: &Value<B>,
state: &State
) -> Result<OneOfTwo<A, B>, LVarList>
pub fn resolve( a: &Value<A>, b: &Value<B>, state: &State ) -> Result<OneOfTwo<A, B>, LVarList>
Attempt to resolve a OneOfTwo
enum from a State
.
Examples:
If neither var is resolved, you’ll get back an Err<LVarList>
suitable for returning from a Constraint::attempt()
.
use canrun::{State, Value, LVarList};
use canrun::constraints::OneOfTwo;
let state = State::new();
let a: Value<usize> = Value::var();
let b: Value<usize> = Value::var();
let resolved = OneOfTwo::resolve(&a, &b, &state);
assert!(resolved.is_err());
If one 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(&b, &Value::new(1)).unwrap();
let resolved = OneOfTwo::resolve(&a, &b, &state);
match resolved {
Ok(OneOfTwo::B(var, b)) => assert_eq!(*b, 1),
}
Errors
Returns a list with either or both [LVar
]s if they are still unresolved.
Auto Trait Implementations§
impl<A, B> RefUnwindSafe for OneOfTwo<A, B>where A: RefUnwindSafe, B: RefUnwindSafe,
impl<A, B> !Send for OneOfTwo<A, B>
impl<A, B> !Sync for OneOfTwo<A, B>
impl<A, B> Unpin for OneOfTwo<A, B>where A: Unpin, B: Unpin,
impl<A, B> UnwindSafe for OneOfTwo<A, B>where A: UnwindSafe + RefUnwindSafe, B: 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