fn reparent_item(&mut self, item: NodeId, parent: NodeId) -> Result<(), TreeError> {
        if self.nodes[&item].parent.is_some() {
            return Err(TreeError::NodeAlreadyHadParent);
        }
        let mut next = Some(parent);
        while let Some(this) = next.take() {
            if this == item {
                return Err(TreeError::EditWouldCauseCycle);
            }
            next = self.nodes[&this].parent;
        }

        self.orphans.remove(&item).unwrap();
        self.nodes[&item].parent = Some(parent);
        Ok(())
    }
// has to recurse up parents to ensure we haven't made any cycles, unfortunately
has to recurse up parents to ensure we haven't made any cycles, unfortunately
has to recurse up parents to ensure we haven ' t made any cycles unfortunately
fn reparent_item(&mut self, item: NodeId, parent: NodeId) -> Result<(), TreeError> {
        if self.nodes[&item].parent.is_some() {
            return Err(TreeError::NodeAlreadyHadParent);
        }
        let mut next = Some(parent);
        while let Some(this) = next.take() {
            if this == item {
                return Err(TreeError::EditWouldCauseCycle);
            }
            next = self.nodes[&this].parent;
        }
        self.orphans.remove(&item).unwrap();
        self.nodes[&item].parent = Some(parent);
        Ok(())
    }
fn reparent_item ( & mut self , item : NodeId , parent : NodeId ) -> Result < ( ) , TreeError > { if self . nodes [ & item ] . parent . is_some ( ) { return Err ( TreeError :: NodeAlreadyHadParent ) ; } let mut next = Some ( parent ) ; while let Some ( this ) = next . take ( ) { if this == item { return Err ( TreeError :: EditWouldCauseCycle ) ; } next = self . nodes [ & this ] . parent ; } self . orphans . remove ( & item ) . unwrap ( ) ; self . nodes [ & item ] . parent = Some ( parent ) ; Ok ( ( ) ) }
has to recurse up parents to ensure we haven't made any cycles, unfortunately
has to recurse up parents to ensure we haven ' t made any cycles unfortunately
&mut self
item
NodeId
parent
NodeId