This repository was archived by the owner on Jun 3, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 6
6
T : OwnedValueDeserialize ,
7
7
{
8
8
// here `s` is a `String`, but pretend we're making
9
- // a network request intead — the point is is that we
9
+ // a network request instead — the point is is that we
10
10
// need to borrow from a local from the function body.
11
11
let value: Value = merde_json:: from_str_via_value ( & s) . map_err ( |e| e. to_static ( ) ) ?;
12
12
Ok ( T :: owned_from_value ( Some ( value) ) ?)
Original file line number Diff line number Diff line change @@ -318,7 +318,10 @@ where
318
318
Some ( Value :: Map ( obj) ) => {
319
319
let mut map = std:: collections:: HashMap :: new ( ) ;
320
320
for ( key, val) in obj. iter ( ) {
321
- let parsed_key = K :: from_str ( key) . map_err ( |_| MerdeError :: InvalidKey ) ?;
321
+ let parsed_key = K :: from_str ( key) . map_err ( |_| MerdeError :: InvalidKey {
322
+ key : key. clone ( ) . into_static ( ) ,
323
+ type_name : std:: any:: type_name :: < K > ( ) ,
324
+ } ) ?;
322
325
let parsed_value = V :: from_value_ref ( Some ( val) ) ?;
323
326
map. insert ( parsed_key, parsed_value) ;
324
327
}
Original file line number Diff line number Diff line change @@ -71,7 +71,10 @@ pub enum MerdeError {
71
71
MissingValue ,
72
72
73
73
/// While calling out to [`FromStr::from_str`](std::str::FromStr::from_str) to build a [`HashMap`](std::collections::HashMap), we got an error.
74
- InvalidKey ,
74
+ InvalidKey {
75
+ key : CowStr < ' static > ,
76
+ type_name : & ' static str ,
77
+ } ,
75
78
76
79
/// While parsing a datetime, we got an error
77
80
InvalidDateTimeValue ,
@@ -111,8 +114,12 @@ impl std::fmt::Display for MerdeError {
111
114
MerdeError :: MissingValue => {
112
115
write ! ( f, "Missing value" )
113
116
}
114
- MerdeError :: InvalidKey => {
115
- write ! ( f, "Invalid key" )
117
+ MerdeError :: InvalidKey { key, type_name } => {
118
+ write ! (
119
+ f,
120
+ "Invalid key: couldn't convert {:?} to type {}" ,
121
+ key, type_name
122
+ )
116
123
}
117
124
MerdeError :: InvalidDateTimeValue => {
118
125
write ! ( f, "Invalid date/time value" )
You can’t perform that action at this time.
0 commit comments