(
data: &syn::DataStruct,
diff_path: &TokenStream2,
)
| 68 | |
| 69 | impl DiffOutput { |
| 70 | pub fn from_struct( |
| 71 | data: &syn::DataStruct, |
| 72 | diff_path: &TokenStream2, |
| 73 | ) -> syn::Result<DiffOutput> { |
| 74 | let fields: Vec<_> = struct_fields(&data.fields).collect(); |
| 75 | |
| 76 | let arms = fields.iter().enumerate().map(|(i, (identifier, _))| { |
| 77 | let index = i as u32; |
| 78 | quote! { |
| 79 | self.#identifier.diff(&baseline.#identifier, path.with(#index), event_queue); |
| 80 | } |
| 81 | }); |
| 82 | |
| 83 | let mut types = TypeSet::default(); |
| 84 | for field in &fields { |
| 85 | types.insert(field.1); |
| 86 | } |
| 87 | |
| 88 | Ok(DiffOutput { |
| 89 | body: quote! { #(#arms)* }, |
| 90 | bounds: types |
| 91 | .into_iter() |
| 92 | .map(move |ty| { |
| 93 | let span = ty.span(); |
| 94 | quote_spanned! {span=> #ty: #diff_path::Diff } |
| 95 | }) |
| 96 | .collect(), |
| 97 | }) |
| 98 | } |
| 99 | |
| 100 | // This is a fair bit more complicated because we need to account for |
| 101 | // three kinds of variants _and_ we need to be able to construct variants |
nothing calls this directly
no test coverage detected