(mask: usize, f: &syn::ItemImpl)
| 646 | |
| 647 | impl SampleImplRewriter { |
| 648 | pub fn rewrite(mask: usize, f: &syn::ItemImpl) -> syn::ItemImpl { |
| 649 | let mut new_impl = f.clone(); |
| 650 | let mut ty_str = String::from("SampleParams<"); |
| 651 | |
| 652 | // based on the mask, form a `SampleParams` type string and add the generic parameters to the `impl<>` generics |
| 653 | // example type string: `"SampleParams<SomeTy<B>, NoneTy, NoneTy>"` |
| 654 | for i in 0..SAMPLE_PARAM_COUNT { |
| 655 | if mask & (1 << i) != 0 { |
| 656 | new_impl.generics.params.push(syn::GenericParam::Type( |
| 657 | syn::Ident::new(SAMPLE_PARAM_GENERICS[i], Span::call_site()).into(), |
| 658 | )); |
| 659 | ty_str.push_str("SomeTy<"); |
| 660 | ty_str.push_str(SAMPLE_PARAM_TYPES[i]); |
| 661 | ty_str.push('>'); |
| 662 | } else { |
| 663 | ty_str.push_str("NoneTy"); |
| 664 | } |
| 665 | ty_str.push(','); |
| 666 | } |
| 667 | ty_str.push('>'); |
| 668 | let ty: syn::Type = syn::parse(ty_str.parse().unwrap()).unwrap(); |
| 669 | |
| 670 | // use the type to insert it into the generic argument of the trait we're implementing |
| 671 | // e.g., `ImageWithMethods<Dummy>` becomes `ImageWithMethods<SampleParams<SomeTy<B>, NoneTy, NoneTy>>` |
| 672 | if let Some(t) = &mut new_impl.trait_ { |
| 673 | if let syn::PathArguments::AngleBracketed(a) = |
| 674 | &mut t.1.segments.last_mut().unwrap().arguments |
| 675 | { |
| 676 | if let Some(syn::GenericArgument::Type(t)) = a.args.last_mut() { |
| 677 | *t = ty.clone(); |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | // rewrite the implemented functions |
| 683 | SampleImplRewriter(mask, ty).visit_item_impl_mut(&mut new_impl); |
| 684 | new_impl |
| 685 | } |
| 686 | |
| 687 | // generates an operands string for use in the assembly, e.g. "Bias %bias Lod %lod", based on the mask |
| 688 | #[allow(clippy::needless_range_loop)] |
nothing calls this directly
no test coverage detected