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
#[derive(Debug)]
pub enum Mofu<T> {
    // NOTE: I am not even sure what this means...
    // For now it just means to default state i.e. no information.
    Normal(Vec<T>),
    Unsafe(Vec<T>),
    Sorted(Vec<T>),
}

impl<T> Default for Mofu<T> {
    fn default() -> Self {
        Mofu::Normal(Vec::default())
    }
}

impl<T> Mofu<T> {
    pub fn guarantee_safe(self) -> Self {
        match self {
            Mofu::Unsafe(x) => Mofu::Normal(x),
            _ => self,
        }
    }

    /////////////////////////////////////////////
    /////
    ///// Vec API Mirror.
    /////
    /////////////////////////////////////////////

    pub fn push(self, item: T) -> Self {
        match self {
            Mofu::Normal(mut x) => {
                x.push(item);
                Mofu::Normal(x)
            }
            Mofu::Unsafe(mut x) => {
                x.push(item);
                Mofu::Unsafe(x)
            }
            Mofu::Sorted(mut x) => {
                x.push(item);
                Mofu::Normal(x)
            }
        }
    }

    pub fn sort(self) -> Self
    where
        T: Ord,
    {
        match self {
            Mofu::Normal(mut x) => {
                x.sort();
                Mofu::Sorted(x)
            }
            Mofu::Unsafe(mut x) => {
                x.sort();
                Mofu::Sorted(x)
            }
            Mofu::Sorted(_) => self,
        }
    }
}