From 200470692ff1023024f0d4a6c35deb43d3045f10 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Mon, 12 Aug 2019 20:39:11 +0100 Subject: Cast SyntaxNodePtr to AstPtr directly --- crates/ra_syntax/src/ptr.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'crates/ra_syntax/src') 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 { pub fn kind(self) -> SyntaxKind { self.kind } + + pub fn cast(self) -> Option> { + if !N::can_cast(self.kind()) { + return None; + } + Some(AstPtr { raw: self, _ty: PhantomData }) + } } /// Like `SyntaxNodePtr`, but remembers the type of node -- cgit v1.2.3