/// Like `SyntaxNodePtr`, but remembers the type of node
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct AstPtr<N: AstNode> {
- ptr: SyntaxNodePtr,
+ raw: SyntaxNodePtr,
_ty: PhantomData<N>,
}
impl<N: AstNode> AstPtr<N> {
pub fn new(node: &N) -> AstPtr<N> {
AstPtr {
- ptr: SyntaxNodePtr::new(node.syntax()),
+ raw: SyntaxNodePtr::new(node.syntax()),
_ty: PhantomData,
}
}
pub fn to_node(self, source_file: &SourceFile) -> &N {
- let syntax_node = self.ptr.to_node(source_file);
+ let syntax_node = self.raw.to_node(source_file);
N::cast(syntax_node).unwrap()
}
pub fn syntax_node_ptr(self) -> SyntaxNodePtr {
- self.ptr
+ self.raw
}
}