aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ptr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ptr.rs')
-rw-r--r--crates/ra_syntax/src/ptr.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs
index 016256075..25824722f 100644
--- a/crates/ra_syntax/src/ptr.rs
+++ b/crates/ra_syntax/src/ptr.rs
@@ -60,6 +60,17 @@ impl<N: AstNode> AstPtr<N> {
60 pub fn syntax_node_ptr(self) -> SyntaxNodePtr { 60 pub fn syntax_node_ptr(self) -> SyntaxNodePtr {
61 self.raw 61 self.raw
62 } 62 }
63
64 // FIXME: extend AstNode to do this safely
65 pub fn cast_checking_kind<U: AstNode>(
66 self,
67 cond: impl FnOnce(SyntaxKind) -> bool,
68 ) -> Option<AstPtr<U>> {
69 if !cond(self.raw.kind()) {
70 return None;
71 }
72 Some(AstPtr { raw: self.raw, _ty: PhantomData })
73 }
63} 74}
64 75
65impl<N: AstNode> From<AstPtr<N>> for SyntaxNodePtr { 76impl<N: AstNode> From<AstPtr<N>> for SyntaxNodePtr {