1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::collections::BTreeMap;
use std::fmt::Display;
use crate::ast::node::Node;
use crate::ast::span::Span;
use crate::traits::identifiable::Identifiable;
use crate::traits::write::Write;

pub trait NodeTrait: Identifiable + Write + Display {

    fn span(&self) -> Span;

    fn children(&self) -> Option<&BTreeMap<usize, Node>>;

    fn has_children(&self) -> bool {
        self.children().map_or(false, |c| c.is_empty())
    }

    fn child(&self, id: usize) -> Option<&Node> {
        self.children().map(|c| c.get(&id)).flatten()
    }
}