1- use functora_tagged:: {
2- ParseError , Refine , RefineError , Tagged ,
3- } ;
1+ use functora_tagged:: { ParseError , Refine , Tagged } ;
42#[ cfg( feature = "serde" ) ]
53use serde:: { Deserialize , Serialize } ;
64use std:: fmt:: Debug ;
75use thiserror:: Error ;
86
9- #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
7+ #[ derive( Eq , PartialEq , Ord , PartialOrd , Clone , Debug ) ]
108pub enum NonEmptyTag { }
11-
129pub type NonEmpty < T > = Tagged < T , NonEmptyTag > ;
1310
14- #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
11+ #[ derive( Eq , PartialEq , Ord , PartialOrd , Clone , Debug ) ]
1512pub enum UserIdTag { }
16-
1713pub type UserId = Tagged < NonEmpty < String > , UserIdTag > ;
1814
19- #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
15+ #[ derive( Eq , PartialEq , Ord , PartialOrd , Clone , Debug ) ]
2016pub enum EmailTag { }
21-
2217pub type Email = Tagged < NonEmpty < String > , EmailTag > ;
2318
24- #[ derive( Debug , Error ) ]
19+ #[ derive(
20+ Eq , PartialEq , Ord , PartialOrd , Clone , Debug , Error ,
21+ ) ]
2522#[ error( "Empty value is not allowed" ) ]
2623pub struct EmptyError ;
2724
2825impl Refine < NonEmptyTag > for String {
29- type RefineErrorRep = EmptyError ;
30- fn refine ( self ) -> Result < Self , Self :: RefineErrorRep > {
26+ type RefineError = EmptyError ;
27+ fn refine ( self ) -> Result < Self , Self :: RefineError > {
3128 if self . is_empty ( ) {
3229 Err ( EmptyError )
3330 } else {
@@ -36,13 +33,13 @@ impl Refine<NonEmptyTag> for String {
3633 }
3734}
3835
39- #[ derive( Debug , Error ) ]
36+ #[ derive( Eq , PartialEq , Ord , PartialOrd , Debug , Error ) ]
4037#[ error( "Invalid UserId format" ) ]
4138pub struct UserIdError ;
4239
4340impl Refine < UserIdTag > for NonEmpty < String > {
44- type RefineErrorRep = UserIdError ;
45- fn refine ( self ) -> Result < Self , Self :: RefineErrorRep > {
41+ type RefineError = UserIdError ;
42+ fn refine ( self ) -> Result < Self , Self :: RefineError > {
4643 let txt = self . rep ( ) ;
4744 if txt. starts_with ( "user_" ) && txt. len ( ) > 5 {
4845 Ok ( self )
@@ -52,13 +49,13 @@ impl Refine<UserIdTag> for NonEmpty<String> {
5249 }
5350}
5451
55- #[ derive( Debug , Error ) ]
56- #[ error( "string too short: {0}, minimum length 3" ) ]
52+ #[ derive( Eq , PartialEq , Ord , PartialOrd , Debug , Error ) ]
53+ #[ error( "String is too short: {0}, minimum length: 3" ) ]
5754pub struct EmailError ( usize ) ;
5855
5956impl Refine < EmailTag > for NonEmpty < String > {
60- type RefineErrorRep = EmailError ;
61- fn refine ( self ) -> Result < Self , Self :: RefineErrorRep > {
57+ type RefineError = EmailError ;
58+ fn refine ( self ) -> Result < Self , Self :: RefineError > {
6259 let len = self . clone ( ) . rep ( ) . len ( ) ;
6360 if len < 3 {
6461 Err ( EmailError ( len) )
@@ -93,7 +90,7 @@ fn test_user_id_refine_failure() {
9390 let inner =
9491 "invalid" . parse :: < NonEmpty < String > > ( ) . unwrap ( ) ;
9592 let err = UserId :: new ( inner) . unwrap_err ( ) ;
96- assert ! ( matches! ( err, RefineError ( _ ) ) ) ;
93+ assert_eq ! ( err, UserIdError ) ;
9794}
9895
9996#[ test]
@@ -118,7 +115,7 @@ fn test_email_success() {
118115fn test_email_refine_failure ( ) {
119116 let inner = "ab" . parse :: < NonEmpty < String > > ( ) . unwrap ( ) ;
120117 let err = Email :: new ( inner) . unwrap_err ( ) ;
121- assert ! ( matches! ( err, RefineError ( _ ) ) ) ;
118+ assert_eq ! ( err, EmailError ( 2 ) ) ;
122119}
123120
124121#[ test]
@@ -176,7 +173,7 @@ fn test_serde_user_id_invalid_refine() {
176173 let toml = r#"user_id = "bad""# ;
177174 let err = toml:: from_str :: < Wrapper > ( toml) . unwrap_err ( ) ;
178175 assert ! (
179- err. to_string( ) . contains( "Refine failed " ) ,
176+ err. to_string( ) . contains( "Invalid UserId format " ) ,
180177 "Unexpected failure: {err}"
181178 ) ;
182179 let toml = r#"user_id = "user_123""# ;
0 commit comments