From 5953a348bd6102a868f303d3f732a6ec7d465833 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Aug 2018 12:38:20 +0300 Subject: Less hackish impl structure --- crates/libsyntax2/src/ast/mod.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'crates/libsyntax2/src/ast/mod.rs') 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 NameRef { ident.leaf_text().unwrap() } } + +impl ImplItem { + pub fn target_type(&self) -> Option> { + match self.target() { + (Some(t), None) | (_, Some(t)) => Some(t), + _ => None, + } + } + + pub fn target_trait(&self) -> Option> { + match self.target() { + (Some(t), Some(_)) => Some(t), + _ => None, + } + } + + fn target(&self) -> (Option>, Option>) { + let mut types = self.syntax().children().filter_map(TypeRef::cast); + let first = types.next(); + let second = types.next(); + (first, second) + } +} -- cgit v1.2.3