diff options
author | Aleksey Kladov <[email protected]> | 2018-08-14 10:38:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-14 10:38:20 +0100 |
commit | 5953a348bd6102a868f303d3f732a6ec7d465833 (patch) | |
tree | 8f4ca16180f850465d871d9b2959d4ae065dcfeb /crates/libsyntax2/src/ast/mod.rs | |
parent | de02d2891ec7f7b295e33887d49de954f677387a (diff) |
Less hackish impl structure
Diffstat (limited to 'crates/libsyntax2/src/ast/mod.rs')
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index f001d340e..679e292a2 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs | |||
@@ -82,3 +82,26 @@ impl<R: TreeRoot> NameRef<R> { | |||
82 | ident.leaf_text().unwrap() | 82 | ident.leaf_text().unwrap() |
83 | } | 83 | } |
84 | } | 84 | } |
85 | |||
86 | impl <R: TreeRoot> ImplItem<R> { | ||
87 | pub fn target_type(&self) -> Option<TypeRef<R>> { | ||
88 | match self.target() { | ||
89 | (Some(t), None) | (_, Some(t)) => Some(t), | ||
90 | _ => None, | ||
91 | } | ||
92 | } | ||
93 | |||
94 | pub fn target_trait(&self) -> Option<TypeRef<R>> { | ||
95 | match self.target() { | ||
96 | (Some(t), Some(_)) => Some(t), | ||
97 | _ => None, | ||
98 | } | ||
99 | } | ||
100 | |||
101 | fn target(&self) -> (Option<TypeRef<R>>, Option<TypeRef<R>>) { | ||
102 | let mut types = self.syntax().children().filter_map(TypeRef::cast); | ||
103 | let first = types.next(); | ||
104 | let second = types.next(); | ||
105 | (first, second) | ||
106 | } | ||
107 | } | ||