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
pub struct Singleton<T> {
    value: T,
}

/// Conversion
impl<T> Singleton<T> {
    pub fn new(value: T) -> Self {
        Self { value }
    }
}

/// Conversion
impl<T> From<T> for Singleton<T> {
    fn from(value: T) -> Self {
        Self { value }
    }
}

/// Semi regular
impl<T> Clone for Singleton<T>
where
    T: Clone,
{
    fn clone(&self) -> Self {
        Self {
            value: self.value.clone(),
        }
    }
}

/// Semi regular
impl<T> Drop for Singleton<T> {
    fn drop(&mut self) {}
}

/// Regular
impl<T> PartialEq for Singleton<T>
where
    T: PartialEq,
{
    fn eq(&self, x: &Self) -> bool {
        self.value.eq(&x.value)
    }
}

/// Regular
impl<T> Eq for Singleton<T> where T: Eq {}

/// Totally-ordered
impl<T> PartialOrd for Singleton<T>
where
    T: PartialOrd,
{
    fn partial_cmp(&self, x: &Self) -> Option<std::cmp::Ordering> {
        self.value.partial_cmp(&x.value)
    }
}

/// Totally-ordered
impl<T> Ord for Singleton<T>
where
    T: Ord,
{
    fn cmp(&self, x: &Self) -> std::cmp::Ordering {
        self.value.cmp(&x.value)
    }
}