Skip to content

Commit

Permalink
feat: search trait bound that ends with Future
Browse files Browse the repository at this point in the history
  • Loading branch information
fMeow committed Mar 28, 2021
1 parent 99cea2c commit 3508ff2
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,15 @@ fn search_trait_bound(
let mut inputs = vec![];

if let TypeParamBound::Trait(trait_bound) = bound {
for segment in &trait_bound.path.segments {
// let segment = &trait_bound.path.segments[0];
let name = segment.ident.to_string();
if name.eq("Future") {
// match Future<Output=Type>
if let PathArguments::AngleBracketed(args) = &segment.arguments {
// binding: Output=Type
if let GenericArgument::Binding(binding) = &args.args[0] {
if let Type::Path(p) = &binding.ty {
inputs.push((generic_type_name.to_owned(), p.path.segments[0].clone()));
}
let segment = &trait_bound.path.segments[trait_bound.path.segments.len() - 1];
let name = segment.ident.to_string();
if name.eq("Future") {
// match Future<Output=Type>
if let PathArguments::AngleBracketed(args) = &segment.arguments {
// binding: Output=Type
if let GenericArgument::Binding(binding) = &args.args[0] {
if let Type::Path(p) = &binding.ty {
inputs.push((generic_type_name.to_owned(), p.path.segments[0].clone()));
}
}
}
Expand Down

0 comments on commit 3508ff2

Please sign in to comment.