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

Function map_payload_fields

validify_derive/src/payload.rs:84–209  ·  view source on GitHub ↗
(
    info: &FieldInfo,
)

Source from the content-addressed store, hash-verified

82}
83
84fn map_payload_fields(
85 info: &FieldInfo,
86) -> (proc_macro2::TokenStream, Option<proc_macro2::TokenStream>) {
87 let ident = info.field.ident.as_ref().unwrap();
88
89 let is_list = info.is_list();
90 let is_option = info.is_option();
91 let is_nested = info.is_nested_validify();
92
93 let ty = &info.field.ty;
94
95 // Grab all serde attributes and attempt to find custom deserializations
96 let serde_attrs = info.serde_attrs();
97 let (custom_serde, serde_attrs) = extract_custom_serde(&serde_attrs);
98
99 let mut custom_de_attr = None;
100 let mut custom_de_tokens = None;
101
102 if let Some(custom_de) = custom_serde {
103 let (custom_de_id, custom_de_toks) =
104 quote_custom_serde_payload_field(ident, ty, custom_de, is_option);
105 let custom_de_id = custom_de_id.to_string();
106 custom_de_attr = Some(quote!(#[serde(deserialize_with = #custom_de_id)]));
107 custom_de_tokens = Some(custom_de_toks);
108 }
109
110 // Grab all remaining attributes
111 let remaining_attrs = info.remaining_attrs();
112
113 if !is_option && !is_nested {
114 return (
115 quote!(
116 #custom_de_attr
117 #(#serde_attrs)*
118 #(#remaining_attrs)*
119 #[validate(required)]
120 #ident: Option<#ty>,
121 ),
122 custom_de_tokens,
123 );
124 }
125
126 if !is_option {
127 let ident = info.field.ident.as_ref().unwrap();
128 let ty = &info.field.ty;
129
130 let syn::Type::Path(mut path) = ty.clone() else {
131 abort!(
132 info.field.span(),
133 "Nested validifes must be structs implementing Validify or collections/options of"
134 )
135 };
136
137 if is_list {
138 payload_path_angle_bracketed(&mut path);
139 } else {
140 let ty_ident = &path.path.segments.last().unwrap().ident;
141 path.path.segments.last_mut().unwrap().ident = format_ident!("{ty_ident}Payload");

Callers 1

generate_structFunction · 0.85

Calls 8

extract_custom_serdeFunction · 0.85
is_listMethod · 0.80
is_optionMethod · 0.80
is_nested_validifyMethod · 0.80
serde_attrsMethod · 0.80
remaining_attrsMethod · 0.80

Tested by

no test coverage detected