fn insert_into_parent(potential_parent: Option<&mut Heading>, heading: &Heading) -> bool {
    match potential_parent {
        None => {
            // No potential parent to insert into so it needs to be insert higher
            false
        }
        Some(parent) => {
            if heading.level <= parent.level {
                // Heading is same level or higher so we don't insert here
                return false;
            }
            if heading.level + 1 == parent.level {
                // We have a direct child of the parent
                parent.children.push(heading.clone());
                return true;
            }
            // We need to go deeper
            if !insert_into_parent(parent.children.iter_mut().last(), heading) {
                // No, we need to insert it here
                parent.children.push(heading.clone());
            }
            true
        }
    }
}
// Takes a potential (mutable) parent and a heading to try and insert into
// Returns true when it performed the insertion, false otherwise
Takes a potential (mutable) parent and a heading to try and insert into
Returns true when it performed the insertion, false otherwise
Takes a potential ( mutable ) parent and a heading to try and insert into Returns true when it performed the insertion false otherwise
fn insert_into_parent(potential_parent: Option<&mut Heading>, heading: &Heading) -> bool {
    match potential_parent {
        None => {
            // No potential parent to insert into so it needs to be insert higher
            false
        }
        Some(parent) => {
            if heading.level <= parent.level {
                // Heading is same level or higher so we don't insert here
                return false;
            }
            if heading.level + 1 == parent.level {
                // We have a direct child of the parent
                parent.children.push(heading.clone());
                return true;
            }
            // We need to go deeper
            if !insert_into_parent(parent.children.iter_mut().last(), heading) {
                // No, we need to insert it here
                parent.children.push(heading.clone());
            }
            true
        }
    }
}
fn insert_into_parent ( potential_parent : Option < & mut Heading > , heading : & Heading ) -> bool { match potential_parent { None => { // No potential parent to insert into so it needs to be insert higher false } Some ( parent ) => { if heading . level <= parent . level { // Heading is same level or higher so we don't insert here return false ; } if heading . level + 1 == parent . level { // We have a direct child of the parent parent . children . push ( heading . clone ( ) ) ; return true ; } // We need to go deeper if ! insert_into_parent ( parent . children . iter_mut ( ) . last ( ) , heading ) { // No, we need to insert it here parent . children . push ( heading . clone ( ) ) ; } true } } }
Takes a potential (mutable) parent and a heading to try and insert into
Returns true when it performed the insertion, false otherwise
Takes a potential ( mutable ) parent and a heading to try and insert into Returns true when it performed the insertion false otherwise
potential_parent
Option<&mut Heading>
heading
&Heading
potential_parent
Option<&mut Heading>
heading
&Heading