aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-30 10:37:03 +0100
committerAleksey Kladov <[email protected]>2018-07-30 10:37:03 +0100
commit423298dddd50d28ce891b10695417401226235a3 (patch)
tree70148e481e13ce2bbc16fc6afeeb9966bd4bd221 /src
parentae849cf134f3ff21261e175d95ba994e86ffe81a (diff)
Trait for tree root
Diffstat (limited to 'src')
-rw-r--r--src/yellow/syntax.rs13
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 @@
1use std::{ 1use std::{
2 fmt, 2 fmt,
3 sync::Arc, 3 sync::Arc,
4 ptr 4 ptr,
5 ops::Deref,
5}; 6};
6 7
7use { 8use {
@@ -10,8 +11,12 @@ use {
10 yellow::{RedNode, GreenNode}, 11 yellow::{RedNode, GreenNode},
11}; 12};
12 13
14pub trait TreeRoot: Deref<Target=SyntaxRoot> + Clone {}
15impl TreeRoot for Arc<SyntaxRoot> {}
16impl<'a> TreeRoot for &'a SyntaxRoot {}
17
13#[derive(Clone, Copy)] 18#[derive(Clone, Copy)]
14pub struct SyntaxNode<ROOT: ::std::ops::Deref<Target=SyntaxRoot> + Clone = Arc<SyntaxRoot>> { 19pub 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
51impl<ROOT: ::std::ops::Deref<Target=SyntaxRoot> + Clone> SyntaxNode<ROOT> { 56impl<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
93impl<ROOT: ::std::ops::Deref<Target=SyntaxRoot> + Clone> fmt::Debug for SyntaxNode<ROOT> { 98impl<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()) {