From 79390798fdb86a6eadfb1e34e1157ee0fe69db34 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 17 Jan 2017 17:35:51 +0900 Subject: validator_derive v0.2 --- validator_derive/src/lib.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'validator_derive') 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!() }; -- cgit v1.2.3