aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/yellow.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-24 23:09:31 +0000
committerAleksey Kladov <[email protected]>2019-01-24 23:09:31 +0000
commit2e354f480b0b83debc06a4311a9709cd8c0df305 (patch)
tree31b772e764f8889ca5d77add0cc3a98e85f92335 /crates/ra_syntax/src/yellow.rs
parentb308375b82a33687f93468d75c7cc628b83a1351 (diff)
use ToOwned trait instead of inherent method
Diffstat (limited to 'crates/ra_syntax/src/yellow.rs')
-rw-r--r--crates/ra_syntax/src/yellow.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs
index a7bfb80e2..ed48739f8 100644
--- a/crates/ra_syntax/src/yellow.rs
+++ b/crates/ra_syntax/src/yellow.rs
@@ -2,10 +2,11 @@ mod builder;
2pub mod syntax_error; 2pub mod syntax_error;
3mod syntax_text; 3mod syntax_text;
4 4
5use std::{fmt, borrow::Borrow};
6
5use self::syntax_text::SyntaxText; 7use self::syntax_text::SyntaxText;
6use crate::{SmolStr, SyntaxKind, TextRange}; 8use crate::{SmolStr, SyntaxKind, TextRange};
7use rowan::{Types, TransparentNewType}; 9use rowan::{Types, TransparentNewType};
8use std::fmt;
9 10
10pub(crate) use self::builder::GreenBuilder; 11pub(crate) use self::builder::GreenBuilder;
11pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; 12pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location};
@@ -25,6 +26,12 @@ pub struct TreeArc<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>(
25 pub(crate) rowan::TreeArc<RaTypes, T>, 26 pub(crate) rowan::TreeArc<RaTypes, T>,
26); 27);
27 28
29impl<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>> Borrow<T> for TreeArc<T> {
30 fn borrow(&self) -> &T {
31 &*self
32 }
33}
34
28impl<T> TreeArc<T> 35impl<T> TreeArc<T>
29where 36where
30 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, 37 T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>,
@@ -124,6 +131,14 @@ impl SyntaxNode {
124 } 131 }
125} 132}
126 133
134impl ToOwned for SyntaxNode {
135 type Owned = TreeArc<SyntaxNode>;
136 fn to_owned(&self) -> TreeArc<SyntaxNode> {
137 let ptr = TreeArc(self.0.to_owned());
138 TreeArc::cast(ptr)
139 }
140}
141
127impl SyntaxNode { 142impl SyntaxNode {
128 pub(crate) fn root_data(&self) -> &Vec<SyntaxError> { 143 pub(crate) fn root_data(&self) -> &Vec<SyntaxError> {
129 self.0.root_data() 144 self.0.root_data()
@@ -133,11 +148,6 @@ impl SyntaxNode {
133 self.0.replace_self(replacement) 148 self.0.replace_self(replacement)
134 } 149 }
135 150
136 pub fn to_owned(&self) -> TreeArc<SyntaxNode> {
137 let ptr = TreeArc(self.0.to_owned());
138 TreeArc::cast(ptr)
139 }
140
141 pub fn kind(&self) -> SyntaxKind { 151 pub fn kind(&self) -> SyntaxKind {
142 self.0.kind() 152 self.0.kind()
143 } 153 }