Cast SyntaxNodePtr to AstPtr directly
This commit is contained in:
committed by
Aleksey Kladov
parent
c8911e872e
commit
200470692f
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user