fn next(&mut self) -> bool {
        let at_child_of_root = self.path.len() == 1;
        let at_last_child_of_root = at_child_of_root && self.path[0] == self.root.len() - 1;
        let at_end = self.side == OutputSide::End;

        let mut parent = Rc::clone(&self.root);
        let mut current_node = Rc::clone(&self.root);
        let mut last_index = 0;
        for index in self.path.iter() {
            let next = Rc::clone(&current_node[*index]);
            parent = current_node;
            current_node = next;
            last_index = *index;
        }

        // Check if we're at the last child of the root. If we're at the End of it, OR it's
        // a collapsed / inlined container OR it's a primitive, then return false.
        if at_last_child_of_root {
            if at_end {
                return false;
            }

            match &current_node.value {
                JValue::Primitive(_) => return false,
                JValue::Container(_, cs) => {
                    if cs.get() != ContainerState::Expanded {
                        return false;
                    }
                }
            }
        }

        match &current_node.value {
            JValue::Container(_, cs) if cs.get() == ContainerState::Expanded && !at_end => {
                // Go to first child of current node if it's expanded.
                self.path.push(0);
                self.side = OutputSide::Start;
            }
            _ => {
                // Otherwise go to next sibling.
                if last_index == parent.len() - 1 {
                    // But if already last sibling, go to End of parent.
                    self.path.pop();
                    self.side = OutputSide::End;
                } else {
                    let i = self.path.len() - 1;
                    self.path[i] += 1;
                    self.side = OutputSide::Start;
                }
            }
        }

        true
    }
// Moves the line ref to the next line in the output.
// Returns whether or not the line was already the last line in the structure.
//
// Rules:
// - If current node is primitive, go to next sibling
// - If current node is inlined/collapsed, go to next sibling
// - If on Start side of expanded container, go to first child
// - If on End side of expanded container, go to next sibling
//
// - When going to next sibling, if current node is the
//   last child, go to the End side of the parent.
//
// - If already on the End side of the root, don't do anything (but return false);
Moves the line ref to the next line in the output.
Returns whether or not the line was already the last line in the structure.

If current node is primitive, go to next sibling
If current node is inlined/collapsed, go to next sibling
If on Start side of expanded container, go to first child
If on End side of expanded container, go to next sibling

When going to next sibling, if current node is the
last child, go to the End side of the parent.

If already on the End side of the root, don't do anything (but return false).
Moves the line ref to the next line in the output . Returns whether or not the line was already the last line in the structure . If current node is primitive go to next sibling If current node is inlined / collapsed go to next sibling If on Start side of expanded container go to first child If on End side of expanded container go to next sibling When going to next sibling if current node is the last child go to the End side of the parent . If already on the End side of the root don ' t do anything ( but return false ) .
fn next(&mut self) -> bool {
        let at_child_of_root = self.path.len() == 1;
        let at_last_child_of_root = at_child_of_root && self.path[0] == self.root.len() - 1;
        let at_end = self.side == OutputSide::End;
        let mut parent = Rc::clone(&self.root);
        let mut current_node = Rc::clone(&self.root);
        let mut last_index = 0;
        for index in self.path.iter() {
            let next = Rc::clone(&current_node[*index]);
            parent = current_node;
            current_node = next;
            last_index = *index;
        }
        // Check if we're at the last child of the root. If we're at the End of it, OR it's
        // a collapsed / inlined container OR it's a primitive, then return false.
        if at_last_child_of_root {
            if at_end {
                return false;
            }
            match &current_node.value {
                JValue::Primitive(_) => return false,
                JValue::Container(_, cs) => {
                    if cs.get() != ContainerState::Expanded {
                        return false;
                    }
                }
            }
        }
        match &current_node.value {
            JValue::Container(_, cs) if cs.get() == ContainerState::Expanded && !at_end => {
                // Go to first child of current node if it's expanded.
                self.path.push(0);
                self.side = OutputSide::Start;
            }
            _ => {
                // Otherwise go to next sibling.
                if last_index == parent.len() - 1 {
                    // But if already last sibling, go to End of parent.
                    self.path.pop();
                    self.side = OutputSide::End;
                } else {
                    let i = self.path.len() - 1;
                    self.path[i] += 1;
                    self.side = OutputSide::Start;
                }
            }
        }
        true
    }
fn next ( & mut self ) -> bool { let at_child_of_root = self . path . len ( ) == 1 ; let at_last_child_of_root = at_child_of_root && self . path [ 0 ] == self . root . len ( ) - 1 ; let at_end = self . side == OutputSide :: End ; let mut parent = Rc :: clone ( & self . root ) ; let mut current_node = Rc :: clone ( & self . root ) ; let mut last_index = 0 ; for index in self . path . iter ( ) { let next = Rc :: clone ( & current_node [ * index ] ) ; parent = current_node ; current_node = next ; last_index = * index ; } // Check if we're at the last child of the root. If we're at the End of it, OR it's // a collapsed / inlined container OR it's a primitive, then return false. if at_last_child_of_root { if at_end { return false ; } match & current_node . value { JValue :: Primitive ( _ ) => return false , JValue :: Container ( _ , cs ) => { if cs . get ( ) != ContainerState :: Expanded { return false ; } } } } match & current_node . value { JValue :: Container ( _ , cs ) if cs . get ( ) == ContainerState :: Expanded && ! at_end => { // Go to first child of current node if it's expanded. self . path . push ( 0 ) ; self . side = OutputSide :: Start ; } _ => { // Otherwise go to next sibling. if last_index == parent . len ( ) - 1 { // But if already last sibling, go to End of parent. self . path . pop ( ) ; self . side = OutputSide :: End ; } else { let i = self . path . len ( ) - 1 ; self . path [ i ] += 1 ; self . side = OutputSide :: Start ; } } } true }
Moves the line ref to the next line in the output.
Moves the line ref to the next line in the output .
&mut self
&mut self