diff options
| author | Vincent Prouillet | 2018-03-20 19:01:23 +0100 |
|---|---|---|
| committer | GitHub | 2018-03-20 19:01:23 +0100 |
| commit | f5b8e9910b9714a5990d173b3a1cc856641ee454 (patch) | |
| tree | e31551babd75ccc41696347370f11c62d4b649c1 /validator_derive/src/quoting.rs | |
| parent | f07c87b0e90f1d2ef8fe806160863ce179d133b7 (diff) | |
| parent | 2911d169468a232e90be81b6a00e21ce18be74b0 (diff) | |
| download | validator-f5b8e9910b9714a5990d173b3a1cc856641ee454.tar.bz2 | |
Merge pull request #44 from csharad/double-option
Support for validating Option<Option<T>>. Fixes #41
Diffstat (limited to 'validator_derive/src/quoting.rs')
| -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 028e864..b6053f4 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 |
