@@ -42,6 +42,18 @@ pub enum VersionizeError {
42
42
Semantic ( String ) ,
43
43
}
44
44
45
+ impl std:: fmt:: Display for VersionizeError {
46
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: result:: Result < ( ) , std:: fmt:: Error > {
47
+ use VersionizeError :: * ;
48
+ match self {
49
+ Io ( e) => write ! ( f, "An IO error occured: {}" , e) ,
50
+ Serialize ( e) => write ! ( f, "A serialization error occured: {}" , e) ,
51
+ Deserialize ( e) => write ! ( f, "A deserialization error occured: {}" , e) ,
52
+ Semantic ( e) => write ! ( f, "A user generated semantic error occured: {}" , e) ,
53
+ }
54
+ }
55
+ }
56
+
45
57
/// Versioned serialization/deserialization result.
46
58
pub type VersionizeResult < T > = std:: result:: Result < T , VersionizeError > ;
47
59
@@ -76,3 +88,17 @@ pub trait Versionize {
76
88
/// Returns latest `Self` version number.
77
89
fn version ( ) -> u16 ;
78
90
}
91
+
92
+ #[ cfg( test) ]
93
+ mod tests {
94
+ #[ test]
95
+ fn test_error_debug_display ( ) {
96
+ // Validates Debug and Display are implemented.
97
+ use VersionizeError :: * ;
98
+ let str = String :: from ( "test" ) ;
99
+ format ! ( "{:?}{}" , Io ( 0 ) , Io ( 0 ) ) ;
100
+ format ! ( "{:?}{}" , Serialize ( str . clone( ) ) , Serialize ( str . clone( ) ) ) ;
101
+ format ! ( "{:?}{}" , Deserialize ( str . clone( ) ) , Deserialize ( str . clone( ) ) ) ;
102
+ format ! ( "{:?}{}" , Semantic ( str . clone( ) ) , Semantic ( str . clone( ) ) ) ;
103
+ }
104
+ }
0 commit comments