All Projects → dtolnay → serde-ignored

dtolnay / serde-ignored

Licence: other
Find out about keys that are ignored when deserializing data

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to serde-ignored

Recap
deserialize typed structures from regex captures
Stars: ✭ 135 (+206.82%)
Mutual labels:  serde
avro-serde-php
Avro Serialisation/Deserialisation (SerDe) library for PHP 7.3+ & 8.0 with a Symfony Serializer integration
Stars: ✭ 43 (-2.27%)
Mutual labels:  serde
kafka-serde-scala
Implicitly converts typeclass encoders to kafka Serializer, Deserializer, Serde.
Stars: ✭ 52 (+18.18%)
Mutual labels:  serde
Weld
Full fake REST API generator written with Rust
Stars: ✭ 146 (+231.82%)
Mutual labels:  serde
Erased Serde
Type-erased Serialize, Serializer and Deserializer traits
Stars: ✭ 201 (+356.82%)
Mutual labels:  serde
serde with
This crate provides custom de/serialization helpers to use in combination with serde's `with`-annotation and with the improved `serde_as`-annotation.
Stars: ✭ 392 (+790.91%)
Mutual labels:  serde
Typical
Typical: Fast, simple, & correct data-validation using Python 3 typing.
Stars: ✭ 111 (+152.27%)
Mutual labels:  serde
roll
RPG dice roller with both Rust CLI and ClojureScript Web interfaces
Stars: ✭ 14 (-68.18%)
Mutual labels:  serde
Cbor
CBOR support for serde.
Stars: ✭ 238 (+440.91%)
Mutual labels:  serde
toml-f
TOML parser implementation for data serialization and deserialization in Fortran
Stars: ✭ 69 (+56.82%)
Mutual labels:  serde
Serde Wasm Bindgen
Native integration of Serde with wasm-bindgen
Stars: ✭ 176 (+300%)
Mutual labels:  serde
Schemars
Generate JSON Schema documents from Rust code
Stars: ✭ 181 (+311.36%)
Mutual labels:  serde
serde dynamodb
Talk with dynamodb using your existing structs thanks to serde
Stars: ✭ 28 (-36.36%)
Mutual labels:  serde
Serde Xml Rs
xml-rs based deserializer for Serde (compatible with 1.0+)
Stars: ✭ 141 (+220.45%)
Mutual labels:  serde
serde
🚝 (unmaintained) A framework for defining, serializing, deserializing, and validating data structures
Stars: ✭ 49 (+11.36%)
Mutual labels:  serde
Serde urlencoded
x-www-form-urlencoded meets Serde
Stars: ✭ 120 (+172.73%)
Mutual labels:  serde
serde-device-tree
Serialize & deserialize device tree binary using serde
Stars: ✭ 20 (-54.55%)
Mutual labels:  serde
kafka-protobuf-serde
Serializer/Deserializer for Kafka to serialize/deserialize Protocol Buffers messages
Stars: ✭ 52 (+18.18%)
Mutual labels:  serde
fitparse-rs
Rust library to parse FIT formatted files
Stars: ✭ 20 (-54.55%)
Mutual labels:  serde
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (-43.18%)
Mutual labels:  serde

Serde ignored

github crates.io docs.rs build status

Find out about keys that are ignored when deserializing data. This crate provides a wrapper that works with any existing Serde Deserializer and invokes a callback on every ignored field.

You can use this to warn users about extraneous keys in a config file, for example.

Note that if you want unrecognized fields to be an error, consider using the #[serde(deny_unknown_fields)] attribute instead.

[dependencies]
serde = "1.0"
serde_ignored = "0.1"
use serde::Deserialize;
use std::collections::{BTreeSet as Set, BTreeMap as Map};

#[derive(Debug, PartialEq, Deserialize)]
struct Package {
    name: String,
    dependencies: Map<String, Dependency>,
}

#[derive(Debug, PartialEq, Deserialize)]
struct Dependency {
    version: String,
}

fn main() {
    let j = r#"{
        "name": "demo",
        "dependencies": {
            "serde": {
                "version": "1.0",
                "typo1": ""
            }
        },
        "typo2": {
            "inner": ""
        },
        "typo3": {}
    }"#;

    // Some Deserializer.
    let jd = &mut serde_json::Deserializer::from_str(j);

    // We will build a set of paths to the unused elements.
    let mut unused = Set::new();

    let p: Package = serde_ignored::deserialize(jd, |path| {
        unused.insert(path.to_string());
    }).unwrap();

    // Deserialized as normal.
    println!("{:?}", p);

    // There were three ignored keys.
    let mut expected = Set::new();
    expected.insert("dependencies.serde.typo1".to_owned());
    expected.insert("typo2".to_owned());
    expected.insert("typo3".to_owned());
    assert_eq!(unused, expected);
}

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].