1- use std:: { error:: Error , sync:: LazyLock } ;
1+ mod email_address;
2+ mod user;
23
3- use fortifier:: Validate ;
4- use regex:: Regex ;
5-
6- static COUNTRY_CODE_REGEX : LazyLock < Regex > =
7- LazyLock :: new ( || Regex :: new ( r"[A-Z]{2}" ) . expect ( "Regex should be valid." ) ) ;
8-
9- #[ derive( Validate ) ]
10- struct CreateUser {
11- #[ validate( email) ]
12- email : String ,
13-
14- #[ validate( length( min = 1 , max = 256 ) ) ]
15- name : String ,
16-
17- #[ validate( url) ]
18- url : String ,
19-
20- #[ validate( regex = & COUNTRY_CODE_REGEX ) ]
21- country_code : String ,
4+ use std:: error:: Error ;
225
23- #[ validate( custom( function = validate_one_locale_required, error = OneLocaleRequiredError ) ) ]
24- #[ validate( length( min = 1 ) ) ]
25- locales : Vec < String > ,
26- }
6+ use fortifier:: Validate ;
277
28- #[ derive( Debug ) ]
29- struct OneLocaleRequiredError ;
30-
31- fn validate_one_locale_required ( locales : & [ String ] ) -> Result < ( ) , OneLocaleRequiredError > {
32- if locales. is_empty ( ) {
33- Err ( OneLocaleRequiredError )
34- } else {
35- Ok ( ( ) )
36- }
37- }
8+ use crate :: { email_address:: ChangeEmailAddressRelation , user:: CreateUser } ;
389
3910#[ tokio:: main]
4011async fn main ( ) -> Result < ( ) , Box < dyn Error > > {
@@ -48,5 +19,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
4819
4920 data. validate ( ) . await ?;
5021
22+ let data = ChangeEmailAddressRelation :: Create {
23+ email_address : "john@doe.com" . to_owned ( ) ,
24+ } ;
25+
26+ data. validate ( ) . await ?;
27+
28+ let data = ChangeEmailAddressRelation :: Update {
29+ id : "1" . to_owned ( ) ,
30+ email_address : "john@doe.com" . to_owned ( ) ,
31+ } ;
32+
33+ data. validate ( ) . await ?;
34+
35+ let data = ChangeEmailAddressRelation :: Delete { id : "1" . to_owned ( ) } ;
36+
37+ data. validate ( ) . await ?;
38+
5139 Ok ( ( ) )
5240}
0 commit comments