1 /// Sources of length limiting values (e.g. "ipv6 payload length field"). 2 #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] 3 pub enum LenSource { 4 /// Limiting length was the slice length (we don't know what determined 5 /// that one originally). 6 Slice, 7 /// Length 8 Ipv4HeaderTotalLen, 9 /// Error occurred in the IPv6 layer. 10 Ipv6HeaderPayloadLen, 11 /// Error occurred while decoding an UDP header. 12 UdpHeaderLen, 13 /// Error occurred while decoding a TCP header. 14 TcpHeaderLen, 15 } 16 17 #[cfg(test)] 18 mod test { 19 use super::LenSource::*; 20 use alloc::format; 21 use std::{ 22 cmp::Ordering, 23 collections::hash_map::DefaultHasher, 24 hash::{Hash, Hasher}, 25 }; 26 27 #[test] debug()28 fn debug() { 29 assert_eq!("Slice", format!("{:?}", Slice)); 30 } 31 32 #[test] clone_eq_hash_ord()33 fn clone_eq_hash_ord() { 34 let layer = Slice; 35 assert_eq!(layer, layer.clone()); 36 let hash_a = { 37 let mut hasher = DefaultHasher::new(); 38 layer.hash(&mut hasher); 39 hasher.finish() 40 }; 41 let hash_b = { 42 let mut hasher = DefaultHasher::new(); 43 layer.clone().hash(&mut hasher); 44 hasher.finish() 45 }; 46 assert_eq!(hash_a, hash_b); 47 assert_eq!(Ordering::Equal, layer.cmp(&layer)); 48 assert_eq!(Some(Ordering::Equal), layer.partial_cmp(&layer)); 49 } 50 } 51