Skip to content

into_new_tree() Panics if Node has no Children #183

@vixi-void

Description

@vixi-void

When NodeMut::into_new_tree() is called on a node that has zero children it panics in NodeMut::try_append_subtree_as_child() during an expect("tree is not empty"). My understanding is that the intention of this expect() call, is to state that at this point, the tree being non-empty is intended to be an invariant. If this is intended to be an invariant, it has been violated. Otherwise, if this is intended behavior, I think that the documentation for NodeMut::into_new_tree() should state that it panics when called on a node with zero children. Here is a minimal example

    use orx_tree::*;

    let mut tree = DynTree::new(0);
    tree.root_mut().push_child(1);
    // Does not panic if we add a children to 1
    // tree.root_mut().children_mut().next().unwrap().push_child(2);
    let tree2: DynTree<_> = tree
        .root_mut()
        .children_mut()
        .nth(0)
        .unwrap()
        .into_new_tree();

I don't have much experience creating issues, so if there's anything else I should have included please let me know. Thank you, I've been enjoying your crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions