From 89416fd17eadd6e04b1b1a6829302e56a4f9a806 Mon Sep 17 00:00:00 2001 From: Sharad Chand Date: Sun, 18 Mar 2018 09:16:24 +0545 Subject: Added assertions for Option> --- validator_derive/src/asserts.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'validator_derive') diff --git a/validator_derive/src/asserts.rs b/validator_derive/src/asserts.rs index 65db5cf..53d76ae 100644 --- a/validator_derive/src/asserts.rs +++ b/validator_derive/src/asserts.rs @@ -1,5 +1,5 @@ -pub static NUMBER_TYPES: [&'static str; 24] = [ +pub static NUMBER_TYPES: [&'static str; 36] = [ "usize", "u8", "u16", "u32", "u64", "isize", "i8", "i16", "i32", "i64", "f32", "f64", @@ -7,6 +7,10 @@ pub static NUMBER_TYPES: [&'static str; 24] = [ "Option", "Option", "Option", "Option", "Option", "Option", "Option", "Option", "Option", "Option", "Option", "Option", + + "Option>", "Option>", "Option>", "Option>", "Option>", + "Option>", "Option>", "Option>", "Option>", "Option>", + "Option>", "Option>", ]; @@ -14,7 +18,9 @@ pub fn assert_string_type(name: &str, field_type: &String) { if field_type != "String" && field_type != "&str" && field_type != "Option" - && !(field_type.starts_with("Option<") && field_type.ends_with("str>")) { + && field_type != "Option>" + && !(field_type.starts_with("Option<") && field_type.ends_with("str>")) + && !(field_type.starts_with("Option>")) { panic!("`{}` validator can only be used on String, &str or an Option of those", name); } } @@ -33,9 +39,12 @@ pub fn assert_has_len(field_name: String, field_type: &String) { if field_type != "String" && !field_type.starts_with("Vec<") && !field_type.starts_with("Option")) + && !(field_type.starts_with("Option>")) && field_type != "&str" { panic!( "Validator `length` can only be used on types `String`, `&str` or `Vec` but found `{}` for field `{}`", -- cgit v1.2.3