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_bfs_style_convenience_methods.rs ]
crate::ix!();

// Provide BFS-style convenience methods:
impl SkeletonNode {
    /// Return numeric ID
    pub fn id(&self) -> u16 {
        match self {
            SkeletonNode::Dispatch { id, .. } => *id,
            SkeletonNode::Aggregate { id, .. } => *id,
            SkeletonNode::LeafHolder { id, .. } => *id,
        }
    }

    /// Return optional parent
    pub fn parent_id(&self) -> Option<u16> {
        match self {
            SkeletonNode::Dispatch { parent_id, .. } => *parent_id,
            SkeletonNode::Aggregate { parent_id, .. } => *parent_id,
            SkeletonNode::LeafHolder { parent_id, .. } => *parent_id,
        }
    }

    /// Return child IDs (empty if LeafHolder)
    pub fn child_ids(&self) -> &[u16] {
        match self {
            SkeletonNode::Dispatch { child_ids, .. } => child_ids,
            SkeletonNode::Aggregate { child_ids, .. } => child_ids,
            SkeletonNode::LeafHolder { .. } => &[],
        }
    }

    /// Return leaf_count (0 if Dispatch/Aggregate)
    pub fn leaf_count(&self) -> u16 {
        match self {
            SkeletonNode::LeafHolder { leaf_count, .. } => *leaf_count,
            _ => 0,
        }
    }

    /// Return capstone only if LeafHolder
    pub fn capstone(&self) -> bool {
        match self {
            SkeletonNode::LeafHolder { capstone, .. } => *capstone,
            _ => false,
        }
    }

    /// Return the node’s display name
    pub fn name(&self) -> &str {
        match self {
            SkeletonNode::Dispatch { name, .. } => name,
            SkeletonNode::Aggregate { name, .. } => name,
            SkeletonNode::LeafHolder { name, .. } => name,
        }
    }

    /// Return the node’s original_key
    pub fn original_key(&self) -> &str {
        match self {
            SkeletonNode::Dispatch { original_key, .. } => original_key,
            SkeletonNode::Aggregate { original_key, .. } => original_key,
            SkeletonNode::LeafHolder { original_key, .. } => original_key,
        }
    }

    /// Return the sub-branch ordering
    pub fn ordering(&self) -> &Option<SubBranchOrdering> {
        match self {
            SkeletonNode::Dispatch { ordering, .. } => ordering,
            SkeletonNode::Aggregate { ordering, .. } => ordering,
            SkeletonNode::LeafHolder { ordering, .. } => ordering,
        }
    }
}