• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::*;
2 use std::vec::Vec;
3 
4 /// Payload of an IP packet.
5 #[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
6 pub struct IpDefragPayloadVec {
7     /// Identifying content of the payload.
8     pub ip_number: IpNumber,
9 
10     /// Length field that was used to determine the length
11     /// of the payload (e.g. IPv6 "payload_length" field).
12     pub len_source: LenSource,
13 
14     /// Payload
15     pub payload: Vec<u8>,
16 }
17 
18 #[cfg(test)]
19 mod test {
20     use super::*;
21     use std::{format, vec};
22 
23     #[test]
debug()24     fn debug() {
25         let s = IpDefragPayloadVec {
26             ip_number: IpNumber::UDP,
27             len_source: LenSource::Slice,
28             payload: vec![],
29         };
30         assert_eq!(
31             format!(
32                 "IpDefragPayloadVec {{ ip_number: {:?}, len_source: {:?}, payload: {:?} }}",
33                 s.ip_number, s.len_source, s.payload
34             ),
35             format!("{:?}", s)
36         );
37     }
38 
39     #[test]
clone_eq_hash_ord()40     fn clone_eq_hash_ord() {
41         let s = IpDefragPayloadVec {
42             ip_number: IpNumber::UDP,
43             len_source: LenSource::Slice,
44             payload: vec![],
45         };
46         assert_eq!(s.clone(), s);
47 
48         use std::collections::hash_map::DefaultHasher;
49         use std::hash::{Hash, Hasher};
50 
51         let a_hash = {
52             let mut hasher = DefaultHasher::new();
53             s.hash(&mut hasher);
54             hasher.finish()
55         };
56         let b_hash = {
57             let mut hasher = DefaultHasher::new();
58             s.clone().hash(&mut hasher);
59             hasher.finish()
60         };
61         assert_eq!(a_hash, b_hash);
62 
63         use std::cmp::Ordering;
64         assert_eq!(s.clone().cmp(&s), Ordering::Equal);
65         assert_eq!(s.clone().partial_cmp(&s), Some(Ordering::Equal));
66     }
67 }
68