etherparse/link/
ether_payload_slice.rs1use crate::*;
2
3#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
5pub struct EtherPayloadSlice<'a> {
6 pub ether_type: EtherType,
8
9 pub len_source: LenSource,
12
13 pub payload: &'a [u8],
15}
16
17#[cfg(test)]
18mod test {
19 use super::*;
20 use alloc::format;
21
22 #[test]
23 fn debug() {
24 let s = EtherPayloadSlice {
25 ether_type: EtherType::IPV4,
26 payload: &[],
27 len_source: LenSource::MacsecShortLength,
28 };
29 assert_eq!(
30 format!(
31 "EtherPayloadSlice {{ ether_type: {:?}, len_source: {:?}, payload: {:?} }}",
32 s.ether_type, s.len_source, s.payload
33 ),
34 format!("{:?}", s)
35 );
36 }
37
38 #[test]
39 fn clone_eq_hash_ord() {
40 let s = EtherPayloadSlice {
41 ether_type: EtherType::IPV4,
42 payload: &[],
43 len_source: LenSource::MacsecShortLength,
44 };
45 assert_eq!(s.clone(), s);
46
47 use std::collections::hash_map::DefaultHasher;
48 use std::hash::{Hash, Hasher};
49
50 let a_hash = {
51 let mut hasher = DefaultHasher::new();
52 s.hash(&mut hasher);
53 hasher.finish()
54 };
55 let b_hash = {
56 let mut hasher = DefaultHasher::new();
57 s.clone().hash(&mut hasher);
58 hasher.finish()
59 };
60 assert_eq!(a_hash, b_hash);
61
62 use std::cmp::Ordering;
63 assert_eq!(s.clone().cmp(&s), Ordering::Equal);
64 assert_eq!(s.clone().partial_cmp(&s), Some(Ordering::Equal));
65 }
66}