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