You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the derive[] variant of Serde to deserialize large files containing various data structures with identical value names.
In this issue, I focus on the value name hidden (I included two of the structs I use in this issue).
In at least one of the data types, the hidden value does not always seem available. Hence, I must use an Optional on that specific hidden value. As I want this to be as strict as possible, I don't want to change all values to an Optional<bool> value, but only if necessary.
Now, if I try to call the from_str function, I encounter the error message:
..called `Result::unwrap()` on an `Err` value: Custom("missing field `@hidden`")
#[derive(Debug,Deserialize,PartialEq,Eq)]pubstructCategoryEntry{#[serde(rename = "@name")]pubname:String,#[serde(rename = "@hidden")]pubhidden:bool, <-------- could fail here
#[serde(rename = "@id")]pubid:String,}#[derive(Debug,Deserialize,PartialEq,Eq)]pubstructInfoLink{#[serde(rename = "@name")]pubname:String,#[serde(rename = "@hidden")]pubhidden:bool, <-------- or here?
}
As multiple struct data types are used in the files' deserialization, I cannot pinpoint which of them the error is occurring.
Is there a way to add a value similar to tags to additionally add to error messages?
For example, if the mentioned error is encountered for deserializing into a CategoryEntry struct, the message could (if possible) look like this:
..called `Result::unwrap()` on an `Err` value: CategoryEntry("missing field `@hidden`")
The text was updated successfully, but these errors were encountered:
I use the
derive[]
variant of Serde to deserialize large files containing various data structures with identical value names.In this issue, I focus on the value name
hidden
(I included two of the structs I use in this issue).In at least one of the data types, the
hidden
value does not always seem available. Hence, I must use anOptional
on that specifichidden
value. As I want this to be as strict as possible, I don't want to change all values to anOptional<bool>
value, but only if necessary.Now, if I try to call the
from_str
function, I encounter the error message:As multiple
struct
data types are used in the files' deserialization, I cannot pinpoint which of them the error is occurring.Is there a way to add a value similar to
tags
to additionally add to error messages?For example, if the mentioned error is encountered for deserializing into a
CategoryEntry
struct, the message could (if possible) look like this:The text was updated successfully, but these errors were encountered: