cairo_lang_syntax/node/stable_ptr.rs
1use salsa::Database;
2
3use super::ids::GreenId;
4use crate::node::SyntaxNode;
5
6/// Stable pointer to a node in the syntax tree.
7///
8/// Has enough information to uniquely define a node in the AST, given the tree.
9/// Has undefined behavior when used with the wrong tree.
10/// This is not a real pointer in the low-level sense, just a representation of the path from the
11/// root to the node.
12/// Stable means that when the AST is changed, pointers of unchanged items tend to stay the same.
13/// For example, if a function is changed, the pointer of an unrelated function in the AST should
14/// remain the same, as much as possible.
15#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
16pub struct SyntaxStablePtr<'a>(SyntaxNode<'a>);
17
18impl<'a> SyntaxStablePtr<'a> {
19 pub fn new(node: SyntaxNode<'a>) -> Self {
20 Self(node)
21 }
22
23 pub fn key_fields(&self, db: &'a dyn Database) -> &'a [GreenId<'a>] {
24 self.0.key_fields(db)
25 }
26}