aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorPhil Ellison <[email protected]>2019-08-12 20:39:11 +0100
committerAleksey Kladov <[email protected]>2019-08-25 10:56:23 +0100
commit200470692ff1023024f0d4a6c35deb43d3045f10 (patch)
tree4243427223e07a9136c764e43c2dbf59f9a73772 /crates/ra_syntax/src
parentc8911e872eb46f811f645190e154b504fac157df (diff)
Cast SyntaxNodePtr to AstPtr directly
Diffstat (limited to 'crates/ra_syntax/src')
-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