1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/// Sources of length limiting values (e.g. "ipv6 payload length field").
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum LenSource {
    /// Limiting length was the slice length (we don't know what determined
    /// that one originally).
    Slice,
    /// Length
    Ipv4HeaderTotalLen,
    /// Error occurred in the IPv6 layer.
    Ipv6HeaderPayloadLen,
    /// Error occurred while decoding an UDP header.
    UdpHeaderLen,
    /// Error occurred while decoding a TCP header.
    TcpHeaderLen,
}

#[cfg(test)]
mod test {
    use super::LenSource::*;
    use alloc::format;
    use std::{
        cmp::Ordering,
        collections::hash_map::DefaultHasher,
        hash::{Hash, Hasher},
    };

    #[test]
    fn debug() {
        assert_eq!("Slice", format!("{:?}", Slice));
    }

    #[test]
    fn clone_eq_hash_ord() {
        let layer = Slice;
        assert_eq!(layer, layer.clone());
        let hash_a = {
            let mut hasher = DefaultHasher::new();
            layer.hash(&mut hasher);
            hasher.finish()
        };
        let hash_b = {
            let mut hasher = DefaultHasher::new();
            layer.clone().hash(&mut hasher);
            hasher.finish()
        };
        assert_eq!(hash_a, hash_b);
        assert_eq!(Ordering::Equal, layer.cmp(&layer));
        assert_eq!(Some(Ordering::Equal), layer.partial_cmp(&layer));
    }
}