From 7060a39d5c8dc2c72fe207536fee649ff615860f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Feb 2019 16:12:15 +0300 Subject: simplify trait bounds --- crates/ra_syntax/src/syntax_node.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index bcfacde72..4d54ae614 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -6,7 +6,10 @@ //! The *real* implementation is in the (language-agnostic) `rowan` crate, this //! modules just wraps its API. -use std::{fmt::{self, Write}, borrow::Borrow}; +use std::{ + fmt::{self, Write}, + borrow::Borrow, +}; use rowan::{Types, TransparentNewType}; @@ -24,14 +27,17 @@ impl Types for RaTypes { type RootData = Vec; } -pub type GreenNode = rowan::GreenNode; +pub(crate) type GreenNode = rowan::GreenNode; + +/// Marker trait for CST and AST nodes +pub trait SyntaxNodeWrapper: TransparentNewType> {} +impl>> SyntaxNodeWrapper for T {} +/// An owning smart pointer for CST or AST node. #[derive(PartialEq, Eq, Hash)] -pub struct TreeArc>>( - pub(crate) rowan::TreeArc, -); +pub struct TreeArc(pub(crate) rowan::TreeArc); -impl>> Borrow for TreeArc { +impl Borrow for TreeArc { fn borrow(&self) -> &T { &*self } @@ -39,11 +45,11 @@ impl>> Borrow for Tre impl TreeArc where - T: TransparentNewType>, + T: SyntaxNodeWrapper, { pub(crate) fn cast(this: TreeArc) -> TreeArc where - U: TransparentNewType>, + U: SyntaxNodeWrapper, { TreeArc(rowan::TreeArc::cast(this.0)) } @@ -51,7 +57,7 @@ where impl std::ops::Deref for TreeArc where - T: TransparentNewType>, + T: SyntaxNodeWrapper, { type Target = T; fn deref(&self) -> &T { @@ -61,7 +67,7 @@ where impl PartialEq for TreeArc where - T: TransparentNewType>, + T: SyntaxNodeWrapper, T: PartialEq, { fn eq(&self, other: &T) -> bool { @@ -72,7 +78,7 @@ where impl Clone for TreeArc where - T: TransparentNewType>, + T: SyntaxNodeWrapper, { fn clone(&self) -> TreeArc { TreeArc(self.0.clone()) @@ -81,7 +87,7 @@ where impl fmt::Debug for TreeArc where - T: TransparentNewType>, + T: SyntaxNodeWrapper, T: fmt::Debug, { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { -- cgit v1.2.3