MCPcopy Create free account
hub / github.com/biblius/validify / collect

Method collect

validify_derive/src/fields.rs:51–86  ·  view source on GitHub ↗

Used by both the `Validate` and `Validify` implementations. Validate ignores the modifiers.

(input: &syn::DeriveInput)

Source from the content-addressed store, hash-verified

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 {

Callers 14

mergeMethod · 0.80
field_errorsMethod · 0.80
schema_errorsMethod · 0.80
validate_emailFunction · 0.80
quote_schema_validationsFunction · 0.80
remaining_attrsMethod · 0.80
serde_attrsMethod · 0.80
str_slice_to_stringFunction · 0.80
str_slice_to_stringFunction · 0.80
deserialize_string_vecFunction · 0.80
can_validate_map_fieldsFunction · 0.80

Calls 4

find_rename_allFunction · 0.85
collect_validationsFunction · 0.85
collect_modifiersFunction · 0.85
find_renameFunction · 0.85

Tested by 7

str_slice_to_stringFunction · 0.64
str_slice_to_stringFunction · 0.64
deserialize_string_vecFunction · 0.64
can_validate_map_fieldsFunction · 0.64
can_validate_set_fieldsFunction · 0.64