pub struct SkippableMap<K, V>(pub HashMap<K, V>);Expand description
The central struct of the library: this is a wrapper around HashMap with a custom
implementation of Deserialize.
The implementation goes through the data to be deserialized, and skips any field which does not
conform to the HashMap<K,V> format.
This means that we can pass a data structure with additional components not in this format which will be skipped.
§Examples
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.0, hm);Tuple Fields§
§0: HashMap<K, V>Implementations§
Trait Implementations§
Source§impl<K, V> AsRef<HashMap<K, V>> for SkippableMap<K, V>
impl<K, V> AsRef<HashMap<K, V>> for SkippableMap<K, V>
Source§impl<K: Clone, V: Clone> Clone for SkippableMap<K, V>
impl<K: Clone, V: Clone> Clone for SkippableMap<K, V>
Source§fn clone(&self) -> SkippableMap<K, V>
fn clone(&self) -> SkippableMap<K, V>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<K: Default, V: Default> Default for SkippableMap<K, V>
impl<K: Default, V: Default> Default for SkippableMap<K, V>
Source§fn default() -> SkippableMap<K, V>
fn default() -> SkippableMap<K, V>
Returns the “default value” for a type. Read more
Source§impl<'de, K, V> Deserialize<'de> for SkippableMap<K, V>
impl<'de, K, V> Deserialize<'de> for SkippableMap<K, V>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<K, V> From<SkippableMap<K, V>> for HashMap<K, V>
impl<K, V> From<SkippableMap<K, V>> for HashMap<K, V>
Source§fn from(value: SkippableMap<K, V>) -> Self
fn from(value: SkippableMap<K, V>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<K, V> Freeze for SkippableMap<K, V>
impl<K, V> RefUnwindSafe for SkippableMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SkippableMap<K, V>
impl<K, V> Sync for SkippableMap<K, V>
impl<K, V> Unpin for SkippableMap<K, V>
impl<K, V> UnwindSafe for SkippableMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more