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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use std::cmp::Ordering;
use crate::{Fqdn, FQDN};
use crate::check::ALPHABET;

impl PartialEq for FQDN
{
    #[inline]
    fn eq(&self, other: &Self) -> bool { self.as_ref().eq(other.as_ref()) }
}

impl Eq for FQDN { }

impl PartialOrd for FQDN
{
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }

    #[inline]
    fn lt(&self, other: &Self) -> bool { self.as_ref().lt(other.as_ref()) }

    #[inline]
    fn le(&self, other: &Self) -> bool { self.as_ref().le(other.as_ref()) }

    #[inline]
    fn gt(&self, other: &Self) -> bool { self.as_ref().gt(other.as_ref()) }

    #[inline]
    fn ge(&self, other: &Self) -> bool { self.as_ref().ge(other.as_ref()) }
}

impl Ord for FQDN
{
    #[inline]
    fn cmp(&self, other: &Self) -> Ordering { self.as_ref().cmp(other.as_ref()) }
}

//--------------------------------------------------------------------------------------

impl PartialOrd<FQDN> for Fqdn
{
    #[inline]
    fn partial_cmp(&self, other: &FQDN) -> Option<Ordering> { self.partial_cmp(other.as_ref()) }
}

impl PartialOrd<Fqdn> for FQDN
{
    #[inline]
    fn partial_cmp(&self, other: &Fqdn) -> Option<Ordering> { self.as_ref().partial_cmp(other) }

    #[inline]
    fn lt(&self, other: &Fqdn) -> bool { self.as_ref().lt(other) }

    #[inline]
    fn le(&self, other: &Fqdn) -> bool { self.as_ref().le(other) }

    #[inline]
    fn gt(&self, other: &Fqdn) -> bool { self.as_ref().gt(other) }

    #[inline]
    fn ge(&self, other: &Fqdn) -> bool { self.as_ref().ge(other) }
}

impl PartialEq<Fqdn> for FQDN
{
    #[inline]
    fn eq(&self, other: &Fqdn) -> bool { self.as_ref().eq(other) }
}

impl PartialEq<FQDN> for Fqdn
{
    #[inline]
    fn eq(&self, other: &FQDN) -> bool { self.eq(other.as_ref()) }
}

//--------------------------------------------------------------------------------------

impl PartialEq for Fqdn
{
    fn eq(&self, other: &Self) -> bool
    {
        let b1 = self.as_bytes();
        let b2 = other.as_bytes();
        (b1.len() == b2.len()) && {
            let i1 = b1.iter().map(|&i| ALPHABET[i as usize]);
            let i2 = b2.iter().map(|&i| ALPHABET[i as usize]);
            i1.eq(i2)
        }
    }
}

impl Eq for Fqdn { }

impl PartialOrd for Fqdn
{
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}

impl Ord for Fqdn
{
    fn cmp(&self, other: &Self) -> Ordering
    {
        let i1 = self.as_bytes().iter().map(|&i| ALPHABET[i as usize]);
        let i2 = other.as_bytes().iter().map(|&i| ALPHABET[i as usize]);
        i1.cmp(i2)
    }
}