use std::{rc::Rc, cell::RefCell};
#[derive(Debug)]
pub struct Node {
pub id: String,
pub name: String,
pub children: Vec<Rc<RefCell<Node>>>,
pub parent: Option<Rc<RefCell<Node>>>,
}
impl Node {
pub fn new<I: Into<String>, N: Into<String>>(id: I, name: N, parent: Option<Rc<RefCell<Node>>>) -> Self {
Self {
id: id.into(),
name: name.into(),
children: Vec::new(),
parent: match parent {
Some(node) => Some(Rc::clone(&node)),
None => None,
},
}
}
pub fn add_child(&mut self, child: Rc<RefCell<Node>>) {
self.children.push(child);
}
pub fn get_children(&self) -> &Vec<Rc<RefCell<Node>>> {
&self.children
}
pub fn is_loaded(&self) -> bool {
!(&self.id.starts_with("submenu_") ^ !self.children.is_empty())
}
}