Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ptr.rs')
-rw-r--r--crates/syntax/src/ptr.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs
index 1d4a89201a..71762996cd 100644
--- a/crates/syntax/src/ptr.rs
+++ b/crates/syntax/src/ptr.rs
@@ -73,6 +73,10 @@ impl<N: AstNode> AstPtr<N> {
Some(AstPtr { raw: self.raw, _ty: PhantomData })
}
+ pub fn kind(&self) -> parser::SyntaxKind {
+ self.raw.kind()
+ }
+
pub fn upcast<M: AstNode>(self) -> AstPtr<M>
where
N: Into<M>,
@@ -84,6 +88,20 @@ impl<N: AstNode> AstPtr<N> {
pub fn try_from_raw(raw: SyntaxNodePtr) -> Option<AstPtr<N>> {
N::can_cast(raw.kind()).then_some(AstPtr { raw, _ty: PhantomData })
}
+
+ pub fn wrap_left<R>(self) -> AstPtr<either::Either<N, R>>
+ where
+ either::Either<N, R>: AstNode,
+ {
+ AstPtr { raw: self.raw, _ty: PhantomData }
+ }
+
+ pub fn wrap_right<L>(self) -> AstPtr<either::Either<L, N>>
+ where
+ either::Either<L, N>: AstNode,
+ {
+ AstPtr { raw: self.raw, _ty: PhantomData }
+ }
}
impl<N: AstNode> From<AstPtr<N>> for SyntaxNodePtr {