mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Shrink PatPtr by swapping its AstPtr and Either wrap order
This commit is contained in:
parent
a158670432
commit
88a00bf49d
15 changed files with 164 additions and 190 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue