pub trait EDeserialize<'de>: Sized + Deserialize<'de> {
// Required method
fn deserialize_for_errors<D>(deserializer: D) -> Result<(), ()>
where D: Deserializer<'de>;
}Expand description
Collect as many deserialization errors as possible in one go.
§Implementing EDeserialize
eserde provides a derive macro to generate an implementation of EDeserialize for your types.
For example:
// 👇 `eserde`'s derive
#[derive(serde::Serialize, eserde::Deserialize)]
struct Point {
x: f64,
y: f64,
}#[derive(eserde::Deserialize)] will implement both eserde::EDeserialize and serde::Deserialize
for your type.
Check out the documentation of the derive macro for more details on
the available attributes and how it interoperates with serde.
§Where does EDeserialize fit in?
serde::Deserialize is designed to abort deserialization as soon as an error is encountered.
This is optimal for speed, but it can result in a frustrating experience for the user,
who has to fix errors one by one.
EDeserialize, instead, is designed to be invoked after serde::Deserialize has
failed to successfully deserialize the value.
EDeserialize will try accumulate as many deserialization errors as possible.
You can then return those errors to the user all at once, enabling them to
fix the payload issues faster.
Required Methods§
Sourcefn deserialize_for_errors<D>(deserializer: D) -> Result<(), ()>where
D: Deserializer<'de>,
fn deserialize_for_errors<D>(deserializer: D) -> Result<(), ()>where
D: Deserializer<'de>,
Visit the input to accumulate as many deserialization errors as possible.
If no error occurred during deserialization, this function will return an empty Ok variant.
If there were errors, instead, it will return an empty Err variant.
Errors are accumulated in thread-local storage.
You can retrieve those errors via ErrorReporter::take_errors.
§Panics
It’ll panic if ErrorReporter::start_deserialization hasn’t been invoked beforehand.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.