diff options
| author | Vincent Prouillet | 2017-01-17 17:35:51 +0900 | 
|---|---|---|
| committer | Vincent Prouillet | 2017-01-17 17:49:51 +0900 | 
| commit | 79390798fdb86a6eadfb1e34e1157ee0fe69db34 (patch) | |
| tree | a9505acface8960b2308b6091f5934f3527ce3a3 | |
| parent | f77863f11ddb358ac8a45a1d7896967e11df1713 (diff) | |
| download | validator-79390798fdb86a6eadfb1e34e1157ee0fe69db34.tar.bz2 | |
validator_derive v0.2
| -rw-r--r-- | validator_derive/src/lib.rs | 20 | 
1 files changed, 15 insertions, 5 deletions
| diff --git a/validator_derive/src/lib.rs b/validator_derive/src/lib.rs index fd02e3d..9725ab6 100644 --- a/validator_derive/src/lib.rs +++ b/validator_derive/src/lib.rs @@ -130,17 +130,27 @@ fn expand_validation(ast: &syn::MacroInput) -> quote::Tokens {      let struct_validation_tokens = match struct_validation {          Some(s) => {              let fn_ident = syn::Ident::new(s.function); -            let skip_on_field_errors = s.skip_on_field_errors; -            quote!( -                if !#skip_on_field_errors || #skip_on_field_errors && errors.len() == 0 { +            if s.skip_on_field_errors { +                quote!( +                    if errors.is_empty() { +                        match #fn_ident(self) { +                            ::std::option::Option::Some((key, val)) => { +                                errors.entry(key).or_insert_with(|| vec![]).push(val) +                            }, +                            ::std::option::Option::None => (), +                        } +                    } +                ) +            } else { +                quote!(                      match #fn_ident(self) {                          ::std::option::Option::Some((key, val)) => {                              errors.entry(key).or_insert_with(|| vec![]).push(val)                          },                          ::std::option::Option::None => (),                      } -                } -            ) +                ) +            }          },          None => quote!()      }; | 
