File tree 1 file changed +17
-5
lines changed 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -438,11 +438,11 @@ impl de::Error for Error {
438
438
439
439
#[ cold]
440
440
fn invalid_type ( unexp : de:: Unexpected , exp : & dyn de:: Expected ) -> Self {
441
- if let de :: Unexpected :: Unit = unexp {
442
- Error :: custom ( format_args ! ( "invalid type: null , expected {}" , exp ) )
443
- } else {
444
- Error :: custom ( format_args ! ( "invalid type: {}, expected {}" , unexp , exp) )
445
- }
441
+ Error :: custom ( format_args ! (
442
+ "invalid type: {} , expected {}" ,
443
+ JsonUnexpected ( unexp ) ,
444
+ exp,
445
+ ) )
446
446
}
447
447
}
448
448
@@ -453,6 +453,18 @@ impl ser::Error for Error {
453
453
}
454
454
}
455
455
456
+ struct JsonUnexpected < ' a > ( de:: Unexpected < ' a > ) ;
457
+
458
+ impl < ' a > Display for JsonUnexpected < ' a > {
459
+ fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
460
+ if let de:: Unexpected :: Unit = self . 0 {
461
+ formatter. write_str ( "null" )
462
+ } else {
463
+ Display :: fmt ( & self . 0 , formatter)
464
+ }
465
+ }
466
+ }
467
+
456
468
// Parse our own error message that looks like "{} at line {} column {}" to work
457
469
// around erased-serde round-tripping the error through de::Error::custom.
458
470
fn make_error ( mut msg : String ) -> Error {
You can’t perform that action at this time.
0 commit comments