tree_sitter_edit/
id.rs

1use tree_sitter::Node;
2
3/// [Newtype][newtype] around [usize], holding values from [`Node::id`].
4///
5/// [newtype]: https://doc.rust-lang.org/rust-by-example/generics/new_types.html
6#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
7pub struct NodeId {
8    pub id: usize,
9}
10
11impl NodeId {
12    #[must_use]
13    pub fn new(node: &Node<'_>) -> Self {
14        NodeId { id: node.id() }
15    }
16
17    #[must_use]
18    pub fn get(&self) -> usize {
19        self.id
20    }
21
22    #[must_use]
23    pub fn is(&self, node: &Node<'_>) -> bool {
24        node.id() == self.get()
25    }
26}