serde-this-or-that
Custom deserialization for fields that can be specified as multiple types.
This crate works with Cargo with a Cargo.toml like:
[]
= "0.5.0"
= { = "1", = ["derive"] }
= "1"
Getting started
Add some usage to your application.
Here's an example of using serde-this-or-that in code:
use Deserialize;
use from_str;
use ;
Exported Functions
as_bool/as_opt_boolas_f64/as_opt_f64as_i64/as_opt_i64as_string/as_opt_stringas_u64/as_opt_u64
Examples
You can check out sample usage of this crate in the examples/ folder in the project repo on GitHub.
Performance
The benchmarks suggest that implementing a custom
Visitor as serde-this-or-that does, performs
on average about 15x better than an approach with an untagged enum.
A separate benchmark compares performance against the serde_with crate:
it indicates both crates perform about the same,
assuming only DisplayFromStr is used.
But when PickFirst is involved, serde-this-or-that appears to
perform about 12x better in an average case.
The benchmarks live in the benches/
folder, and can be run with cargo bench.
Optionals
The extra helper functions that begin with as_opt, return an Option<T> of the respective data type T,
rather than the type T itself (see #4).
On success, they return a value of T wrapped in
Some.
On error, or when there is a null value, or one of an invalid data type, the
as_opt helper functions return None instead.
Contributing
Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.
Check out the Contributing section in the docs for more info.
License
This project is proudly licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).
serde-this-or-that can be distributed according to the MIT license. Contributions
will be accepted under the same license.