Cast SyntaxNodePtr to AstPtr directly

This commit is contained in:
Phil Ellison
2019-08-12 20:39:11 +01:00
committed by Aleksey Kladov
parent c8911e872e
commit 200470692f
2 changed files with 10 additions and 14 deletions

View File

@@ -31,6 +31,13 @@ impl SyntaxNodePtr {
pub fn kind(self) -> SyntaxKind {
self.kind
}
pub fn cast<N: AstNode>(self) -> Option<AstPtr<N>> {
if !N::can_cast(self.kind()) {
return None;
}
Some(AstPtr { raw: self, _ty: PhantomData })
}
}
/// Like `SyntaxNodePtr`, but remembers the type of node