Crates.io | zisvalidator_derive |
lib.rs | zisvalidator_derive |
version | 0.1.6 |
source | src |
created_at | 2021-04-10 11:01:59.379515 |
updated_at | 2021-05-09 07:46:27.984359 |
description | Derive macro for zisvalidator |
homepage | |
repository | https://github.com/zzhengzhuo/zisvalidator.git |
max_upload_size | |
id | 381660 |
size | 36,790 |
Zisvalidator is designed for validating input struct or enum in web or other scence.
Reference to Serde and Validator.
#[derive(Validate)]
struct S(String); //validate tuple struct with 1 element
#[derive(Validate)]
struct S(String,u64,); //validate tuple struct with mulitple elements
#[derive(Validate)]
struct S{ //validate struct with fields
str:String
}
#[derive(Validate)]
enum E{ //validate enum
S(String), //validate tuple varient with 1 element
Tuple(String,String,), //validate tuple varient with multiple element
Nested{ //validate varient with fields
field:String,
}
}
#[validate(schema = "foo")]
Validate type T by customer by function foo
as Fn(t:T) -> Result<(),ValidatorError)
#[validate(custom = "foo")]
Valid for tuple struct.For example,for type struct S(String,String)
,validate by function foo
as Fn(t:&String) -> Result<(),ValidatorError>
#[validate(range = "start..end")]
Valid for tuple struct.Validate for elements' range.
#[validate(range = "start..end")]
Validate for fields' range.
#[validate(custom = "foo")]
Validate by function foo
as Fn(t:&T) -> Result<(),ValidatorError>
.
#[validate(range = "start..end")]
Validate for variants' range.
#[validate(custom = "foo")]
Validate by function foo
as Fn(t:&T) -> Result<(),ValidatorError>
.