fn to_string(&self) -> String {
        let mut string = format!("({}", self.data.to_string());
        let mut stack = self.siblings.clone();
        let mut depth_stack = vec![];
        stack.reverse();

        while let Some(next) = stack.pop() {
            if !next.borrow().siblings.is_empty() {
                string.push_str(&format!(" ({}", next.borrow().data.to_string()));
                let mut siblings = next.borrow().siblings.clone();
                depth_stack.push(siblings.len() - 1);
                siblings.reverse();
                stack.extend_from_slice(&siblings);
            } else {
                string.push_str(&format!(" ({})", next.borrow().data.to_string()));
                while let Some(depth) = depth_stack.last_mut() {
                    if *depth == 0 {
                        depth_stack.pop();
                        string.push_str(")");
                    } else {
                        *depth -= 1;
                        break;
                    }
                }
            }
        }

        while let Some(_) = depth_stack.last() {
            depth_stack.pop();
            string.push_str(")");
        }

        string.push_str(")");
        string
    }
/// Converts tree to s-expression string.
///
/// Each node will be wrapped in parentheses, with it's value
/// going first, and subnodes afterwards.
///
/// # Examples
///
/// ```
/// let root = Tree::new(0);
/// Tree::push_child(&root, 1);
/// Tree::push_child(&root, 2);
///
/// assert_eq!(&root.borrow().to_string(), "(0 (1) (2))");
/// ```
///
Converts tree to s-expression string.
Each node will be wrapped in parentheses, with it's value
going first, and subnodes afterwards.
Converts tree to s - expression string . Each node will be wrapped in parentheses with it ' s value going first and subnodes afterwards .
fn to_string(&self) -> String {
        let mut string = format!("({}", self.data.to_string());
        let mut stack = self.siblings.clone();
        let mut depth_stack = vec![];
        stack.reverse();
        while let Some(next) = stack.pop() {
            if !next.borrow().siblings.is_empty() {
                string.push_str(&format!(" ({}", next.borrow().data.to_string()));
                let mut siblings = next.borrow().siblings.clone();
                depth_stack.push(siblings.len() - 1);
                siblings.reverse();
                stack.extend_from_slice(&siblings);
            } else {
                string.push_str(&format!(" ({})", next.borrow().data.to_string()));
                while let Some(depth) = depth_stack.last_mut() {
                    if *depth == 0 {
                        depth_stack.pop();
                        string.push_str(")");
                    } else {
                        *depth -= 1;
                        break;
                    }
                }
            }
        }
        while let Some(_) = depth_stack.last() {
            depth_stack.pop();
            string.push_str(")");
        }
        string.push_str(")");
        string
    }
fn to_string ( & self ) -> String { let mut string = format ! ( " " self data to_string ( ) ) ; let mut stack = self . siblings . clone ( ) ; let mut depth_stack = vec ! [ ] ; stack . reverse ( ) ; while let Some ( next ) = stack . pop ( ) { if ! next . borrow ( ) . siblings . is_empty ( ) { string . push_str ( & format ! ( " " next borrow ( ) data to_string ( ) ) ) ; let mut siblings = next . borrow ( ) . siblings . clone ( ) ; depth_stack . push ( siblings . len ( ) - 1 ) ; siblings . reverse ( ) ; stack . extend_from_slice ( & siblings ) ; } else { string . push_str ( & format ! ( " " next borrow ( ) data to_string ( ) ) ) ; while let Some ( depth ) = depth_stack . last_mut ( ) { if * depth == 0 { depth_stack . pop ( ) ; string . push_str ( " " ) ; } else { * depth -= 1 ; break ; } } } } while let Some ( _ ) = depth_stack . last ( ) { depth_stack . pop ( ) ; string . push_str ( " " ) ; } string . push_str ( " " ) ; string }
Converts tree to s-expression string.
Converts tree to s - expression string .
&self
examples
None