diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/yellow/syntax.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/yellow/syntax.rs b/src/yellow/syntax.rs index 0fa24fb47..c31b832d0 100644 --- a/src/yellow/syntax.rs +++ b/src/yellow/syntax.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | fmt, | 2 | fmt, |
3 | sync::Arc, | 3 | sync::Arc, |
4 | ptr | 4 | ptr, |
5 | ops::Deref, | ||
5 | }; | 6 | }; |
6 | 7 | ||
7 | use { | 8 | use { |
@@ -10,8 +11,12 @@ use { | |||
10 | yellow::{RedNode, GreenNode}, | 11 | yellow::{RedNode, GreenNode}, |
11 | }; | 12 | }; |
12 | 13 | ||
14 | pub trait TreeRoot: Deref<Target=SyntaxRoot> + Clone {} | ||
15 | impl TreeRoot for Arc<SyntaxRoot> {} | ||
16 | impl<'a> TreeRoot for &'a SyntaxRoot {} | ||
17 | |||
13 | #[derive(Clone, Copy)] | 18 | #[derive(Clone, Copy)] |
14 | pub struct SyntaxNode<ROOT: ::std::ops::Deref<Target=SyntaxRoot> + Clone = Arc<SyntaxRoot>> { | 19 | pub struct SyntaxNode<ROOT: TreeRoot = Arc<SyntaxRoot>> { |
15 | pub(crate) root: ROOT, | 20 | pub(crate) root: ROOT, |
16 | // guaranteed to be alive bc SyntaxRoot holds a strong ref | 21 | // guaranteed to be alive bc SyntaxRoot holds a strong ref |
17 | red: ptr::NonNull<RedNode>, | 22 | red: ptr::NonNull<RedNode>, |
@@ -48,7 +53,7 @@ impl SyntaxNode<Arc<SyntaxRoot>> { | |||
48 | } | 53 | } |
49 | } | 54 | } |
50 | 55 | ||
51 | impl<ROOT: ::std::ops::Deref<Target=SyntaxRoot> + Clone> SyntaxNode<ROOT> { | 56 | impl<ROOT: TreeRoot> SyntaxNode<ROOT> { |
52 | pub fn borrow<'a>(&'a self) -> SyntaxNode<&'a SyntaxRoot> { | 57 | pub fn borrow<'a>(&'a self) -> SyntaxNode<&'a SyntaxRoot> { |
53 | SyntaxNode { | 58 | SyntaxNode { |
54 | root: &*self.root, | 59 | root: &*self.root, |
@@ -90,7 +95,7 @@ impl<ROOT: ::std::ops::Deref<Target=SyntaxRoot> + Clone> SyntaxNode<ROOT> { | |||
90 | } | 95 | } |
91 | } | 96 | } |
92 | 97 | ||
93 | impl<ROOT: ::std::ops::Deref<Target=SyntaxRoot> + Clone> fmt::Debug for SyntaxNode<ROOT> { | 98 | impl<ROOT: TreeRoot> fmt::Debug for SyntaxNode<ROOT> { |
94 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | 99 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
95 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; | 100 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; |
96 | if has_short_text(self.kind()) { | 101 | if has_short_text(self.kind()) { |