Expand description
deserr
Deserr is a crate for deserializing data, with the ability to return custom, type-specific errors upon failure. It was also designed with user-facing APIs in mind and thus provides better defaults than serde for this use case.
Unlike serde, deserr does not parse the data in its serialization format itself but offloads the work to other crates. Instead, it deserializes the already-parsed serialized data into the final type. For example:
// bytes of the serialized value
let s: &str = ".." ;
// parse serialized data using another crate, such as `serde_json`
let json: serde_json::Value = serde_json::from_str(s).unwrap();
// finally deserialize with deserr
let data = T::deserialize_from_value(json.into_value()).unwrap();
// `T` must implement `Deserr`.
You may be looking for:
§FAQ
§But why?
At Meilisearch, we wanted to customize the error code we return when we fail the deserialization of a specific field. Some error messages were also not clear at all and impossible to edit.
§What about the maintenance?
At Meilisearch we’re already using deserr in production; thus, it’s well maintained.
§Where can I see more examples of usage of this crate?
Currently, you can read our examples in the examples
directory of this repository.
You can also look at our integration test; each attribute has a simple-to-read test.
And obviously, you can read the code of Meilisearch where deserr is used on all our routes.
§My question is not listed
Please, if you think there is a bug in this lib or would like a new feature, open an issue or a discussion. If you would like to chat more directly with us, you can join us on discord at https://discord.com/invite/meilisearch
§The logo
The logo was graciously offered and crafted by @irevoire ’s sister after a lot of back and forth. Many thanks to her.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Modules§
- errors
- This module holds some pre-made error types to eases your usage of deserr
- serde_
cs - serde_
json
Structs§
- Value
Pointer - The owned version of a
ValuePointerRef
.
Enums§
- Error
Kind - Value
Value<V>
is a view into the parsed serialization data (of typeV
) that is readable by Deserr.- Value
Kind - Equivalent to
Value
but without the associated data. - Value
Pointer Ref - A location within a
Value
.
Traits§
- Deserialize
Error - A trait for errors returned by
deserialize_from_value
. - Deserr
- A trait for types that can be deserialized from a
Value
. The generic type parameterE
is the custom error that is returned when deserialization fails. - Into
Value - A trait for a value that can be deserialized via [
Deserr
]. - Map
- A keyed map of values conforming to
IntoValue
. - Merge
With Error - A trait which describes how to combine two errors together.
- Sequence
- A sequence of values conforming to
IntoValue
.
Functions§
- deserialize
- Deserialize the given value.
- take_
cf_ content - Extract the
ControlFlow
result if it’s the same type.
Derive Macros§
- Deserr
- It is possible to derive the
Deserr
trait for structs and enums with named fields. The derive proc macro accept many arguments, explained below: