capability-skeleton 0.1.0

A Rust library for managing and building complex hierarchical tree structures such as skill trees. Supports serialization, error handling, and deep tree metrics.
Documentation
// ---------------- [ File: capability-skeleton/src/skeleton_node_set_child_ids.rs ]
crate::ix!();

impl SkeletonNode {

    /// Mutate `child_ids`, turning this node into `Dispatch` if needed.
    /// If `new_child_ids` is empty, we switch to `LeafHolder` with leaf_count=0.
    pub fn set_child_ids(&mut self, new_child_ids: Vec<u16>) {
        if new_child_ids.is_empty() {
            // become a LeafHolder if no children
            match self {
                SkeletonNode::LeafHolder { .. } => {
                    // already a LeafHolder, do nothing or set leaf_count=0
                }
                SkeletonNode::Dispatch { 
                    id, parent_id, name, original_key, ordering, ..
                } => {
                    *self = SkeletonNode::LeafHolder {
                        id: *id,
                        parent_id: *parent_id,
                        leaf_count: 0,
                        capstone: false,
                        name: name.clone(),
                        original_key: original_key.clone(),
                        ordering: ordering.clone(),
                    };
                }
                SkeletonNode::Aggregate { 
                    id, parent_id, name, original_key, ordering, ..
                } => {
                    *self = SkeletonNode::LeafHolder {
                        id: *id,
                        parent_id: *parent_id,
                        leaf_count: 0,
                        capstone: false,
                        name: name.clone(),
                        original_key: original_key.clone(),
                        ordering: ordering.clone(),
                    };
                }
            }
        } else {
            // become Dispatch if we have new children
            match self {
                SkeletonNode::Dispatch { child_ids, .. } => {
                    *child_ids = new_child_ids;
                }
                SkeletonNode::Aggregate { 
                    id, parent_id, name, original_key, ordering, ..
                } => {
                    *self = SkeletonNode::Dispatch {
                        id: *id,
                        parent_id: *parent_id,
                        child_ids: new_child_ids,
                        name: name.clone(),
                        original_key: original_key.clone(),
                        ordering: ordering.clone(),
                    };
                }
                SkeletonNode::LeafHolder {
                    id, parent_id, name, original_key, ordering, ..
                } => {
                    *self = SkeletonNode::Dispatch {
                        id: *id,
                        parent_id: *parent_id,
                        child_ids: new_child_ids,
                        name: name.clone(),
                        original_key: original_key.clone(),
                        ordering: ordering.clone(),
                    };
                }
            }
        }
    }
}