skippable_map 0.1.1

deserialize wrapper around HashMap which skips non-conforming data
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 3 items with examples
  • Size
  • Source code size: 11.91 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.72 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 23s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • tveness/skippable_map
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • tveness

skippable_map

Crates.io Documentation Build status License

This crate provides a wrapper around HashMap with a custom implementation of Deserialize which skips any field which does not conform to the structure of the HashMap, rather than throwing an error.

This liberal approach to deserializing data is helpful if attempting to extract a subset of information being passed in. For example a JSON blob with a mixed structure which cannot be controlled, but a specific set of entries is of interest.

Example

use serde_json;
use skippable_map::SkippableMap;
use std::collections::HashMap;
                                                                                                
let json = r#"{ "string": "b", "number": 1, "other_number": 2, "negative_number": -44}"#;
// SkippableMap<String, u64> will skip the (String, String) entry, and the negative number
let just_numbers: SkippableMap<String, u64> = serde_json::from_str(json).unwrap();
let hm = HashMap::from([
    (String::from("number"), 1_u64),
    (String::from("other_number"), 2_u64),
]);
                                                                                                
assert_eq!(just_numbers.as_ref(), &hm);
assert_eq!(just_numbers.0, hm);
// Consumes just_numbers to produce inner HashMap
assert_eq!(just_numbers.inner(), hm);