@@ -20,7 +20,7 @@ use base64::{engine::general_purpose::STANDARD, Engine};
2020
2121use crate :: {
2222 external_models:: normalized_string:: NormalizedString ,
23- validation:: { FailureReason , Validate , ValidationContext , ValidationResult } ,
23+ validation:: { Validate , ValidationContext , ValidationResult } ,
2424} ;
2525
2626#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -60,12 +60,10 @@ impl Validate for AttachedText {
6060 ( Encoding :: Base64 , Err ( _) ) => {
6161 let context = context. with_struct ( "AttachedText" , "content" ) ;
6262
63- results. push ( ValidationResult :: Failed {
64- reasons : vec ! [ FailureReason {
65- message: "Content is not Base64 encoded" . to_string( ) ,
66- context,
67- } ] ,
68- } )
63+ results. push ( ValidationResult :: failure (
64+ "Content is not Base64 encoded" ,
65+ context,
66+ ) )
6967 }
7068 ( Encoding :: UnknownEncoding ( _) , _) => {
7169 let context = context. with_struct ( "AttachedText" , "encoding" ) ;
@@ -109,20 +107,15 @@ impl Encoding {
109107impl Validate for Encoding {
110108 fn validate_with_context ( & self , context : ValidationContext ) -> ValidationResult {
111109 match self {
112- Encoding :: UnknownEncoding ( _) => ValidationResult :: Failed {
113- reasons : vec ! [ FailureReason {
114- message: "Unknown encoding" . to_string( ) ,
115- context,
116- } ] ,
117- } ,
110+ Encoding :: UnknownEncoding ( _) => ValidationResult :: failure ( "Unknown encoding" , context) ,
118111 _ => ValidationResult :: Passed ,
119112 }
120113 }
121114}
122115
123116#[ cfg( test) ]
124117mod test {
125- use crate :: models:: attached_text:: Encoding ;
118+ use crate :: { models:: attached_text:: Encoding , validation :: FailureReason } ;
126119
127120 use super :: * ;
128121 use pretty_assertions:: assert_eq;
@@ -168,17 +161,14 @@ mod test {
168161 validation_result,
169162 ValidationResult :: Failed {
170163 reasons: vec![
171- FailureReason {
172- message:
173- "NormalizedString contains invalid characters \\ r \\ n \\ t or \\ r\\ n"
174- . to_string( ) ,
175- context: ValidationContext :: new( )
176- . with_struct( "AttachedText" , "content_type" )
177- } ,
178- FailureReason {
179- message: "Content is not Base64 encoded" . to_string( ) ,
180- context: ValidationContext :: new( ) . with_struct( "AttachedText" , "content" )
181- }
164+ FailureReason :: new(
165+ "NormalizedString contains invalid characters \\ r \\ n \\ t or \\ r\\ n" ,
166+ ValidationContext :: new( ) . with_struct( "AttachedText" , "content_type" )
167+ ) ,
168+ FailureReason :: new(
169+ "Content is not Base64 encoded" ,
170+ ValidationContext :: new( ) . with_struct( "AttachedText" , "content" )
171+ )
182172 ]
183173 }
184174 ) ;
0 commit comments