Used by both the `Validate` and `Validify` implementations. Validate ignores the modifiers.
(input: &syn::DeriveInput)
| 49 | |
| 50 | /// Used by both the `Validate` and `Validify` implementations. Validate ignores the modifiers. |
| 51 | pub fn collect(input: &syn::DeriveInput) -> Vec<Self> { |
| 52 | let syn::Data::Struct(syn::DataStruct { ref fields, .. }) = input.data else { |
| 53 | abort!( |
| 54 | input.span(), |
| 55 | "#[derive(Validate/Validify)] can only be used on structs with named fields" |
| 56 | ) |
| 57 | }; |
| 58 | |
| 59 | let rename_rule = crate::serde::find_rename_all(&input.attrs); |
| 60 | |
| 61 | fields |
| 62 | .into_iter() |
| 63 | .map(|field| { |
| 64 | let field_ident = field |
| 65 | .ident |
| 66 | .as_ref() |
| 67 | .expect("Found unnamed field") |
| 68 | .to_string(); |
| 69 | |
| 70 | let validations = collect_validations(field); |
| 71 | let modifiers = collect_modifiers(field); |
| 72 | |
| 73 | // The original name refers to the field name set with serde rename. |
| 74 | let original_name = crate::serde::find_rename(field); |
| 75 | |
| 76 | Self::new( |
| 77 | field.clone(), |
| 78 | field_ident, |
| 79 | original_name, |
| 80 | validations, |
| 81 | modifiers, |
| 82 | rename_rule, |
| 83 | ) |
| 84 | }) |
| 85 | .collect::<Vec<_>>() |
| 86 | } |
| 87 | |
| 88 | /// Returns the field name or the name from serde rename. Used for errors. |
| 89 | pub fn name(&self) -> String { |