Crate deserr

Crate deserr 

Source
Expand description

deserr

License License Crates.io Docs dependency status

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 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§

ValuePointer
The owned version of a ValuePointerRef.

Enums§

ErrorKind
Value
Value<V> is a view into the parsed serialization data (of type V) that is readable by Deserr.
ValueKind
Equivalent to Value but without the associated data.
ValuePointerRef
A location within a Value.

Traits§

DeserializeError
A trait for errors returned by deserialize_from_value.
Deserr
A trait for types that can be deserialized from a Value. The generic type parameter E is the custom error that is returned when deserialization fails.
IntoValue
A trait for a value that can be deserialized via [Deserr].
Map
A keyed map of values conforming to IntoValue.
MergeWithError
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: