diff options
| author | Sharad Chand | 2018-03-18 09:16:59 +0545 |
|---|---|---|
| committer | Sharad Chand | 2018-03-18 09:16:59 +0545 |
| commit | c4c325ef653126a5d0150a3aff03f9cef03a6d6e (patch) | |
| tree | 020de3db2ea25f1473239a0744aea128a792a02b /validator_derive/src | |
| parent | 89416fd17eadd6e04b1b1a6829302e56a4f9a806 (diff) | |
| download | validator-c4c325ef653126a5d0150a3aff03f9cef03a6d6e.tar.bz2 | |
Optional validator params and wraping for Option<Option<T>>
Diffstat (limited to 'validator_derive/src')
| -rw-r--r-- | validator_derive/src/quoting.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/validator_derive/src/quoting.rs b/validator_derive/src/quoting.rs index bf2a531..2ffade8 100644 --- a/validator_derive/src/quoting.rs +++ b/validator_derive/src/quoting.rs @@ -40,7 +40,8 @@ impl FieldQuoter { pub fn get_optional_validator_param(&self) -> quote::Tokens { let ident = &self.ident; - if self._type.starts_with("Option<&") || NUMBER_TYPES.contains(&self._type.as_ref()) { + if self._type.starts_with("Option<&") || self._type.starts_with("Option<Option<&") + || NUMBER_TYPES.contains(&self._type.as_ref()) { quote!(#ident) } else { quote!(ref #ident) @@ -52,7 +53,13 @@ impl FieldQuoter { pub fn wrap_if_option(&self, tokens: quote::Tokens) -> quote::Tokens { let field_ident = &self.ident; let optional_pattern_matched = self.get_optional_validator_param(); - if self._type.starts_with("Option<") { + if self._type.starts_with("Option<Option<") { + return quote!( + if let Some(Some(#optional_pattern_matched)) = self.#field_ident { + #tokens + } + ) + } else if self._type.starts_with("Option<") { return quote!( if let Some(#optional_pattern_matched) = self.#field_ident { #tokens |
