From 423298dddd50d28ce891b10695417401226235a3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Jul 2018 12:37:03 +0300 Subject: Trait for tree root --- src/yellow/syntax.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') 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 @@ use std::{ fmt, sync::Arc, - ptr + ptr, + ops::Deref, }; use { @@ -10,8 +11,12 @@ use { yellow::{RedNode, GreenNode}, }; +pub trait TreeRoot: Deref + Clone {} +impl TreeRoot for Arc {} +impl<'a> TreeRoot for &'a SyntaxRoot {} + #[derive(Clone, Copy)] -pub struct SyntaxNode + Clone = Arc> { +pub struct SyntaxNode> { pub(crate) root: ROOT, // guaranteed to be alive bc SyntaxRoot holds a strong ref red: ptr::NonNull, @@ -48,7 +53,7 @@ impl SyntaxNode> { } } -impl + Clone> SyntaxNode { +impl SyntaxNode { pub fn borrow<'a>(&'a self) -> SyntaxNode<&'a SyntaxRoot> { SyntaxNode { root: &*self.root, @@ -90,7 +95,7 @@ impl + Clone> SyntaxNode { } } -impl + Clone> fmt::Debug for SyntaxNode { +impl fmt::Debug for SyntaxNode { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; if has_short_text(self.kind()) { -- cgit v1.2.3