fn pathvar2proj(&mut self, pv: PathVar) -> PolarResult<Projection> {
        let PathVar { mut path, var } = pv;
        // new var with empty path
        let mut pv = PathVar::from(var);
        // what type is the base variable?
        let mut typ = match self.get_type(pv.clone()) {
            Some(typ) => typ,
            _ => return invalid_state(format!("unknown type for `{}`", pv.var)),
        };

        // the last part of the path is always allowed not to be a relation.
        // pop it off for now & deal with it in a minute.
        let field = path.pop();

        // all the middle parts have to be relations, so if we can't find one
        // then we fail here.
        for dot in path {
            match self.get_relation_def(&typ, &dot) {
                None => return df_field_missing(&typ, &dot),
                Some(rel) => {
                    let Relation(_, name, right) = &rel;
                    typ = right.clone();
                    pv.path.push(name.clone());
                    self.entities.insert(pv.clone(), right.clone());
                    self.relations.insert(rel);
                }
            }
        }

        // if the last path component names a relation from typ to typ'
        // then typ' is the new type and field is None. otherwise,
        // typ & field stay the same.
        match field
            .as_ref()
            .and_then(|dot| self.get_relation_def(&typ, dot))
        {
            None => Ok(Projection(typ, field)),
            Some(rel) => {
                let tag = rel.2.clone();
                pv.path.push(rel.1.clone());
                self.entities.insert(pv, tag.clone());
                self.relations.insert(rel);
                Ok(Projection(tag, None))
            }
        }
    }
/// turn a pathvar into a projection.
/// populates relations as a side effect
turn a pathvar into a projection.
populates relations as a side effect
turn a pathvar into a projection . populates relations as a side effect
fn pathvar2proj(&mut self, pv: PathVar) -> PolarResult<Projection> {
        let PathVar { mut path, var } = pv;
        // new var with empty path
        let mut pv = PathVar::from(var);
        // what type is the base variable?
        let mut typ = match self.get_type(pv.clone()) {
            Some(typ) => typ,
            _ => return invalid_state(format!("unknown type for `{}`", pv.var)),
        };
        // the last part of the path is always allowed not to be a relation.
        // pop it off for now & deal with it in a minute.
        let field = path.pop();
        // all the middle parts have to be relations, so if we can't find one
        // then we fail here.
        for dot in path {
            match self.get_relation_def(&typ, &dot) {
                None => return df_field_missing(&typ, &dot),
                Some(rel) => {
                    let Relation(_, name, right) = &rel;
                    typ = right.clone();
                    pv.path.push(name.clone());
                    self.entities.insert(pv.clone(), right.clone());
                    self.relations.insert(rel);
                }
            }
        }
        // if the last path component names a relation from typ to typ'
        // then typ' is the new type and field is None. otherwise,
        // typ & field stay the same.
        match field
            .as_ref()
            .and_then(|dot| self.get_relation_def(&typ, dot))
        {
            None => Ok(Projection(typ, field)),
            Some(rel) => {
                let tag = rel.2.clone();
                pv.path.push(rel.1.clone());
                self.entities.insert(pv, tag.clone());
                self.relations.insert(rel);
                Ok(Projection(tag, None))
            }
        }
    }
fn pathvar2proj ( & mut self , pv : PathVar ) -> PolarResult < Projection > { let PathVar { mut path , var } = pv ; // new var with empty path let mut pv = PathVar :: from ( var ) ; // what type is the base variable? let mut typ = match self . get_type ( pv . clone ( ) ) { Some ( typ ) => typ , _ => return invalid_state ( format ! ( " " pv var ) ) , } ; // the last part of the path is always allowed not to be a relation. // pop it off for now & deal with it in a minute. let field = path . pop ( ) ; // all the middle parts have to be relations, so if we can't find one // then we fail here. for dot in path { match self . get_relation_def ( & typ , & dot ) { None => return df_field_missing ( & typ , & dot ) , Some ( rel ) => { let Relation ( _ , name , right ) = & rel ; typ = right . clone ( ) ; pv . path . push ( name . clone ( ) ) ; self . entities . insert ( pv . clone ( ) , right . clone ( ) ) ; self . relations . insert ( rel ) ; } } } // if the last path component names a relation from typ to typ' // then typ' is the new type and field is None. otherwise, // typ & field stay the same. match field . as_ref ( ) . and_then ( | dot | self . get_relation_def ( & typ , dot ) ) { None => Ok ( Projection ( typ , field ) ) , Some ( rel ) => { let tag = rel . 2 . clone ( ) ; pv . path . push ( rel . 1 . clone ( ) ) ; self . entities . insert ( pv , tag . clone ( ) ) ; self . relations . insert ( rel ) ; Ok ( Projection ( tag , None ) ) } } }
turn a pathvar into a projection.
turn a pathvar into a projection .
&mut self
pv
PathVar
&mut self
pv
PathVar