MCPcopy Create free account
hub / github.com/BillyDM/Firewheel / from_struct

Method from_struct

crates/firewheel-macros/src/diff.rs:70–98  ·  view source on GitHub ↗
(
        data: &syn::DataStruct,
        diff_path: &TokenStream2,
    )

Source from the content-addressed store, hash-verified

68
69impl 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

Callers

nothing calls this directly

Calls 4

struct_fieldsFunction · 0.85
collectMethod · 0.80
into_iterMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected