jppe/encode/impls_hashset.rs
1// use std::collections::HashSet;
2
3
4// impl<T: crate::ByteEncode> crate::ByteEncode for HashSet<T> {
5// fn encode(&self, input: &mut Vec<u8>, cattr: Option<&crate::ContainerAttrModifiers>, fattr: Option<&crate::FieldAttrModifiers>) {
6// for value in self {
7// T::encode(value, input, cattr, fattr);
8// }
9// }
10// }
11
12
13// impl<T: crate::BorrowByteEncode> crate::BorrowByteEncode for HashSet<T> {
14// fn encode(&self, input: &mut Vec<u8>, cattr: Option<&crate::ContainerAttrModifiers>, fattr: Option<&crate::FieldAttrModifiers>) {
15// for value in self {
16// T::encode(value, input, cattr, fattr);
17// }
18// }
19// }
20
21
22// #[cfg(test)]
23// mod tests {
24// use crate::encode::ByteEncode;
25// use super::*;
26
27// #[test]
28// fn test_encode_hashset() {
29// let hashset = HashSet::<u16>::from([1, 2]);
30// let mut buf = vec![];
31// hashset.encode(&mut buf, None, None);
32// // hashset is out of order.
33// assert!(buf == b"\x00\x01\x00\x02" || buf == b"\x00\x02\x00\x01" );
34
35// let hashset = HashSet::from(["1".as_bytes(), b"2"]);
36// let mut buf = vec![];
37// hashset.encode(&mut buf, None, None);
38// // hashset is out of order.
39// assert!(buf == b"\x31\x32" || buf == b"\x32\x31" );
40// }
41// }