etherparse/
len_source.rs

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