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

Method wrap_modifier_if_collection

validify_derive/src/fields.rs:276–301  ·  view source on GitHub ↗

Wrap the quoted output of a modification in a for loop if the field type is a collection.

(
        &self,
        param: proc_macro2::TokenStream,
        tokens: proc_macro2::TokenStream,
        modifier: &Modifier,
    )

Source from the content-addressed store, hash-verified

274 /// Wrap the quoted output of a modification in a for loop if
275 /// the field type is a collection.
276 pub fn wrap_modifier_if_collection(
277 &self,
278 param: proc_macro2::TokenStream,
279 tokens: proc_macro2::TokenStream,
280 modifier: &Modifier,
281 ) -> proc_macro2::TokenStream {
282 if !self.is_list() {
283 return tokens;
284 }
285
286 let modified = match modifier {
287 Modifier::Trim => quote!(el.trim().to_string()),
288 Modifier::Uppercase => quote!(el.to_uppercase()),
289 Modifier::Lowercase => quote!(el.to_lowercase()),
290 Modifier::Capitalize => {
291 quote!(::std::format!("{}{}", &el[0..1].to_uppercase(), &el[1..]))
292 }
293 _ => unreachable!("modifier is never wrapped"),
294 };
295
296 quote!(
297 for el in #param.iter_mut() {
298 *el = #modified
299 }
300 )
301 }
302
303 /// Return all the field's attributes that are unrelated to validify and serde
304 pub fn remaining_attrs(&self) -> Vec<&syn::Attribute> {

Callers 1

to_validify_tokensMethod · 0.80

Calls 1

is_listMethod · 0.80

Tested by

no test coverage detected