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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
use serde::Serialize;

pub mod data;
pub mod file;
pub mod front_side;
pub mod reverse_side;
pub mod selfie;
pub mod translation_file;
pub mod unspecified;

pub use {
    data::Data,
    file::{File, Files},
    front_side::FrontSide,
    reverse_side::ReverseSide,
    selfie::Selfie,
    translation_file::{TranslationFile, TranslationFiles},
    unspecified::Unspecified,
};

/// Reperesents possible sources of an error.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize)]
#[serde(rename_all = "snake_case", tag = "source")]
// todo: #[non_exhaustive]
pub enum Source<'a> {
    /// An error with data.
    Data(Data<'a>),
    /// An error with a front side.
    FrontSide(FrontSide<'a>),
    /// An error with a reverse side.
    ReverseSide(ReverseSide<'a>),
    /// An error with a selfie.
    Selfie(Selfie<'a>),
    /// An error with a file.
    File(File<'a>),
    /// An error with several files.
    Files(Files<'a>),
    /// An error with a translation file.
    TranslationFile(TranslationFile<'a>),
    /// An error with translation files.
    TranslationFiles(TranslationFiles<'a>),
    /// An unspecified error.
    Unspecified(Unspecified<'a>),
}

impl<'a> Source<'a> {
    /// Checks if `self` is `Data`.
    pub fn is_data(self) -> bool {
        match self {
            Source::Data {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `FrontSide`.
    pub fn is_front_side(self) -> bool {
        match self {
            Source::FrontSide {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `ReverseSide`.
    pub fn is_reverse_side(self) -> bool {
        match self {
            Source::ReverseSide {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Selfie`.
    pub fn is_selfie(self) -> bool {
        match self {
            Source::Selfie {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `File`.
    pub fn is_file(self) -> bool {
        match self {
            Source::File {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Files`.
    pub fn is_files(self) -> bool {
        match self {
            Source::Files {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `TranslationFile`.
    pub fn is_translation_file(self) -> bool {
        match self {
            Source::TranslationFile {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `TranslationFiles`.
    pub fn is_translation_files(self) -> bool {
        match self {
            Source::TranslationFiles {
                ..
            } => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Unspecified`.
    pub fn is_unspecified(self) -> bool {
        match self {
            Source::Unspecified {
                ..
            } => true,
            _ => false,
        }
    }
}

impl<'a> From<Data<'a>> for Source<'a> {
    fn from(source: Data<'a>) -> Self {
        Source::Data(source)
    }
}

impl<'a> From<FrontSide<'a>> for Source<'a> {
    fn from(source: FrontSide<'a>) -> Self {
        Source::FrontSide(source)
    }
}

impl<'a> From<ReverseSide<'a>> for Source<'a> {
    fn from(source: ReverseSide<'a>) -> Self {
        Source::ReverseSide(source)
    }
}

impl<'a> From<Selfie<'a>> for Source<'a> {
    fn from(source: Selfie<'a>) -> Self {
        Source::Selfie(source)
    }
}

impl<'a> From<File<'a>> for Source<'a> {
    fn from(source: File<'a>) -> Self {
        Source::File(source)
    }
}

impl<'a> From<Files<'a>> for Source<'a> {
    fn from(source: Files<'a>) -> Self {
        Source::Files(source)
    }
}

impl<'a> From<TranslationFile<'a>> for Source<'a> {
    fn from(source: TranslationFile<'a>) -> Self {
        Source::TranslationFile(source)
    }
}

impl<'a> From<TranslationFiles<'a>> for Source<'a> {
    fn from(source: TranslationFiles<'a>) -> Self {
        Source::TranslationFiles(source)
    }
}

impl<'a> From<Unspecified<'a>> for Source<'a> {
    fn from(source: Unspecified<'a>) -> Self {
        Source::Unspecified(source)
    }
}