use std::collections::HashSet; use beserial::{Deserialize, DeserializeWithLength, Serialize, SerializeWithLength}; #[test] fn it_correctly_serializes_and_deserializes_hashsets() { fn reserialize(s: HashSet) -> HashSet where T: Serialize + Deserialize + std::cmp::Eq + std::hash::Hash { let mut v = Vec::with_capacity(64); SerializeWithLength::serialize::>(&s, &mut v).unwrap(); let s2: HashSet = DeserializeWithLength::deserialize::(&mut &v[..]).unwrap(); return s2; } let mut hashset = HashSet::new(); hashset.insert(18446744073709551615u64); hashset.insert(9223372036854775807); hashset.insert(381073568934759237); hashset.insert(2131907967678687); hashset.insert(255); hashset.insert(16); let reference_hashset = hashset.clone(); let processed_hashset = reserialize(hashset); assert_eq!(reference_hashset, processed_hashset); assert!(processed_hashset.contains(&18446744073709551615)); assert!(processed_hashset.contains(&9223372036854775807)); assert!(processed_hashset.contains(&381073568934759237)); assert!(processed_hashset.contains(&2131907967678687)); assert!(processed_hashset.contains(&255)); assert!(processed_hashset.contains(&16)); assert!(!processed_hashset.contains(&0)); }