Parse field info from struct
(input: &mut DeriveInput)
| 64 | |
| 65 | /// Parse field info from struct |
| 66 | fn parse_fields(input: &mut DeriveInput) -> Result<FieldInfo> { |
| 67 | let syn::Data::Struct(struc) = &mut input.data else { |
| 68 | bail_span!(input, "#[pystruct_sequence_data] can only be on a struct") |
| 69 | }; |
| 70 | |
| 71 | let syn::Fields::Named(fields) = &mut struc.fields else { |
| 72 | bail_span!( |
| 73 | input, |
| 74 | "#[pystruct_sequence_data] can only be on a struct with named fields" |
| 75 | ); |
| 76 | }; |
| 77 | |
| 78 | let mut parsed_fields = Vec::with_capacity(fields.named.len()); |
| 79 | |
| 80 | for field in &mut fields.named { |
| 81 | let mut skip = false; |
| 82 | let mut unnamed = false; |
| 83 | let mut attrs_to_remove = Vec::new(); |
| 84 | let mut cfg_attrs = Vec::new(); |
| 85 | |
| 86 | for (i, attr) in field.attrs.iter().enumerate() { |
| 87 | // Collect cfg attributes for conditional compilation |
| 88 | if attr.path().is_ident("cfg") { |
| 89 | cfg_attrs.push(attr.clone()); |
| 90 | continue; |
| 91 | } |
| 92 | |
| 93 | if !attr.path().is_ident("pystruct_sequence") { |
| 94 | continue; |
| 95 | } |
| 96 | |
| 97 | let Ok(meta) = attr.parse_meta() else { |
| 98 | continue; |
| 99 | }; |
| 100 | |
| 101 | let Meta::List(l) = meta else { |
| 102 | bail_span!(input, "Only #[pystruct_sequence(...)] form is allowed"); |
| 103 | }; |
| 104 | |
| 105 | let idents: Vec<_> = l |
| 106 | .nested |
| 107 | .iter() |
| 108 | .filter_map(|n| n.get_ident()) |
| 109 | .cloned() |
| 110 | .collect(); |
| 111 | |
| 112 | for ident in idents { |
| 113 | match ident.to_string().as_str() { |
| 114 | "skip" => { |
| 115 | skip = true; |
| 116 | } |
| 117 | "unnamed" => { |
| 118 | unnamed = true; |
| 119 | } |
| 120 | _ => { |
| 121 | bail_span!(ident, "Unknown item for #[pystruct_sequence(...)]") |
| 122 | } |
| 123 | } |
no test coverage detected