anymap-serde 0.1.0

Low overhead AnyMap with serde-backed serialization of stored values
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#[cfg(test)]
mod tests {
    use anymap_serde::SerializableAnyMap;

    #[test]
    fn entry_should_be_removed_if_deserialization_fails() {
        let json = r#"{ "usize": "foo" }"#.to_string();
        let mut m: SerializableAnyMap = serde_json::from_str(&json).unwrap();

        assert!(m.contains::<usize>()); // Entry exists before deserialization, we can't know it's invalid yet
        assert!(m.entry::<usize>().into_occupied().is_none()); // Once deserialization is attempted, it will fail and we know it was invalid
        assert!(!m.contains::<usize>()); // Entry is removed after failed deserialization
    }
}