pub fn unify_var(&self, v1: &Var, v2: &Var) -> PossibleStates<T> {
        let b1 = self.bindings.get(&v1.index);
        let b2 = self.bindings.get(&v2.index);

        match b1 {
            Some(s1) => { // v1 has a slot
                match b2 {
                    Some(s2) => { // both variables have slots
                        let value1 = self.slots.get(s1);
                        let value2 = self.slots.get(s2);

                        match value1 {
                            Some(vv1) => {
                                match value2 {
                                    Some(ref vv2) => vv1.unify(vv2, self), // both v1 and v2 are bound, unify values
                                    None => PossibleStates::new()    // v2 is not bound, this is an error
                                }
                            },
                            None => {
                                match value2 {
                                    Some(_vv2) => PossibleStates::new(), // v1 is not bound, this is an error
                                    None => if s1.eq(s2) { vec![self.clone()] }
                                            else { PossibleStates::new() } // neither slot is bound; slots must then be equal
                                }
                            }
                        }
                    },
                    None => { // v1 has a slot, v2 does not
                        vec![State {
                            bindings: self.bindings.insert(v2.index, *s1).unwrap(),
                            slots: self.slots.clone(),
                            .. *self
                        }]
                    }
                }
            },
            None => { // v1 does not have a slot
                match b2 {
                    Some(s2) => { // v1 does not have a slot, v2 does
                        vec![State {
                            bindings: self.bindings.insert(v1.index, *s2).unwrap(),
                            slots: self.slots.clone(),
                            .. *self
                        }]
                    },
                    None => { // neither variable has a slot
                        let slot = &v1.index;
                        vec![State {
                            bindings: self.bindings
                                        .insert(v1.index, *slot).unwrap()
                                        .insert(v2.index, *slot).unwrap(),
                            slots: self.slots.clone(),
                            .. *self
                        }]
                    }
                }
            }
        }
    }
/// Attempts to unify two variables.
Attempts to unify two variables.
Attempts to unify two variables .
pub fn unify_var(&self, v1: &Var, v2: &Var) -> PossibleStates<T> {
        let b1 = self.bindings.get(&v1.index);
        let b2 = self.bindings.get(&v2.index);
        match b1 {
            Some(s1) => { // v1 has a slot
                match b2 {
                    Some(s2) => { // both variables have slots
                        let value1 = self.slots.get(s1);
                        let value2 = self.slots.get(s2);
                        match value1 {
                            Some(vv1) => {
                                match value2 {
                                    Some(ref vv2) => vv1.unify(vv2, self), // both v1 and v2 are bound, unify values
                                    None => PossibleStates::new()    // v2 is not bound, this is an error
                                }
                            },
                            None => {
                                match value2 {
                                    Some(_vv2) => PossibleStates::new(), // v1 is not bound, this is an error
                                    None => if s1.eq(s2) { vec![self.clone()] }
                                            else { PossibleStates::new() } // neither slot is bound; slots must then be equal
                                }
                            }
                        }
                    },
                    None => { // v1 has a slot, v2 does not
                        vec![State {
                            bindings: self.bindings.insert(v2.index, *s1).unwrap(),
                            slots: self.slots.clone(),
                            .. *self
                        }]
                    }
                }
            },
            None => { // v1 does not have a slot
                match b2 {
                    Some(s2) => { // v1 does not have a slot, v2 does
                        vec![State {
                            bindings: self.bindings.insert(v1.index, *s2).unwrap(),
                            slots: self.slots.clone(),
                            .. *self
                        }]
                    },
                    None => { // neither variable has a slot
                        let slot = &v1.index;
                        vec![State {
                            bindings: self.bindings
                                        .insert(v1.index, *slot).unwrap()
                                        .insert(v2.index, *slot).unwrap(),
                            slots: self.slots.clone(),
                            .. *self
                        }]
                    }
                }
            }
        }
    }
pub fn unify_var ( & self , v1 : & Var , v2 : & Var ) -> PossibleStates < T > { let b1 = self . bindings . get ( & v1 . index ) ; let b2 = self . bindings . get ( & v2 . index ) ; match b1 { Some ( s1 ) => { // v1 has a slot match b2 { Some ( s2 ) => { // both variables have slots let value1 = self . slots . get ( s1 ) ; let value2 = self . slots . get ( s2 ) ; match value1 { Some ( vv1 ) => { match value2 { Some ( ref vv2 ) => vv1 . unify ( vv2 , self ) , // both v1 and v2 are bound, unify values None => PossibleStates :: new ( ) // v2 is not bound, this is an error } } , None => { match value2 { Some ( _vv2 ) => PossibleStates :: new ( ) , // v1 is not bound, this is an error None => if s1 . eq ( s2 ) { vec ! [ self clone ( ) ] } else { PossibleStates :: new ( ) } // neither slot is bound; slots must then be equal } } } } , None => { // v1 has a slot, v2 does not vec ! [ State { bindings self bindings insert ( v2 index s1 ) unwrap ( ) slots self slots clone ( ) self } ] } } } , None => { // v1 does not have a slot match b2 { Some ( s2 ) => { // v1 does not have a slot, v2 does vec ! [ State { bindings self bindings insert ( v1 index s2 ) unwrap ( ) slots self slots clone ( ) self } ] } , None => { // neither variable has a slot let slot = & v1 . index ; vec ! [ State { bindings self bindings insert ( v1 index slot ) unwrap ( ) insert ( v2 index slot ) unwrap ( ) slots self slots clone ( ) self } ] } } } } }
Attempts to unify two variables.
Attempts to unify two variables .
&self
v1
&Var
v2
&Var
&self
v1
&Var
v2
&Var