diffus/edit/
enm.rs

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
#[cfg_attr(feature = "serialize-impl", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)]
pub enum Edit<'a, T: ?Sized, Diff> {
    Copy(&'a T),
    VariantChanged(&'a T, &'a T),
    AssociatedChanged(Diff),
}

impl<'a, T: ?Sized, Diff> Edit<'a, T, Diff> {
    pub fn is_copy(&self) -> bool {
        if let Self::Copy(_) = self {
            true
        } else {
            false
        }
    }

    pub fn is_variant_changed(&self) -> bool {
        if let Self::VariantChanged(_, _) = self {
            true
        } else {
            false
        }
    }

    pub fn is_associated_changed(&self) -> bool {
        if let Self::AssociatedChanged(_) = self {
            true
        } else {
            false
        }
    }

    pub fn variant_changed(&self) -> Option<(&'a T, &'a T)> {
        if let Self::VariantChanged(left, right) = self {
            Some((left, right))
        } else {
            None
        }
    }

    pub fn associated_change(&self) -> Option<&Diff> {
        if let Self::AssociatedChanged(value) = self {
            Some(value)
        } else {
            None
        }
    }
}