Skip to content

Commit

Permalink
allow any string value (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
cortopy committed Feb 19, 2022
1 parent 06c2f4e commit 47908fe
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions validator_derive/src/asserts.rs
Expand Up @@ -70,14 +70,7 @@ pub static NUMBER_TYPES: [&str; 38] = [
];

pub fn assert_string_type(name: &str, type_name: &str, field_type: &syn::Type) {
if type_name != "String"
&& type_name != "&str"
&& !COW_TYPE.is_match(type_name)
&& type_name != "Option<String>"
&& type_name != "Option<Option<String>>"
&& !(type_name.starts_with("Option<") && type_name.ends_with("str>"))
&& !(type_name.starts_with("Option<Option<") && type_name.ends_with("str>>"))
{
if !type_name.contains("String") && !type_name.contains("str") {
abort!(
field_type.span(),
"`{}` validator can only be used on String, &str, Cow<'_,str> or an Option of those",
Expand Down Expand Up @@ -113,17 +106,13 @@ pub fn assert_has_len(field_name: String, type_name: &str, field_type: &syn::Typ
return;
}

if type_name != "String"
if !type_name.contains("String")
&& !type_name.contains("str")
&& !type_name.starts_with("Vec<")
&& !type_name.starts_with("Option<Vec<")
&& !type_name.starts_with("Option<Option<Vec<")
&& type_name != "Option<String>"
&& type_name != "Option<Option<String>>"
// a bit ugly
&& !(type_name.starts_with("Option<") && type_name.ends_with("str>"))
&& !(type_name.starts_with("Option<Option<") && type_name.ends_with("str>>"))
&& !COW_TYPE.is_match(type_name)
&& type_name != "&str"
{
abort!(field_type.span(),
"Validator `length` can only be used on types `String`, `&str`, Cow<'_,str> or `Vec` but found `{}` for field `{}`",
Expand Down

0 comments on commit 47908fe

Please sign in to comment.