diff options
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 | } | ||