aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ptr.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs
index d24660ac3..992034ef0 100644
--- a/crates/ra_syntax/src/ptr.rs
+++ b/crates/ra_syntax/src/ptr.rs
@@ -31,6 +31,13 @@ impl SyntaxNodePtr {
31 pub fn kind(self) -> SyntaxKind { 31 pub fn kind(self) -> SyntaxKind {
32 self.kind 32 self.kind
33 } 33 }
34
35 pub fn cast<N: AstNode>(self) -> Option<AstPtr<N>> {
36 if !N::can_cast(self.kind()) {
37 return None;
38 }
39 Some(AstPtr { raw: self, _ty: PhantomData })
40 }
34} 41}
35 42
36/// Like `SyntaxNodePtr`, but remembers the type of node 43/// Like `SyntaxNodePtr`, but remembers the type of node