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
// libovgu-canteen - A canteen parser module for ovgu.
//
// Copyright (C) 2017
//     Fin Christensen <christensen.fin@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

use crate::{Error, IdentifierKind};
use serde::{Serialize, Deserialize};
use std;

/// This enum represents allergenics that are contained in a meal.
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[allow(missing_docs)]
pub enum Allergenic {
    Wheat,
    Rye,
    Barley,
    Oat,
    Spelt,
    Kamut,
    Crustacean,
    Egg,
    Fish,
    Peanut,
    Soya,
    Lactose,
    Almond,
    Hazelnut,
    Walnut,
    Cashew,
    PecanNut,
    BrazilNut,
    Pistachio,
    MacadamiaNut,
    QueenslandNut,
    Celery,
    Mustard,
    Sesame,
    Sulphite,
    Lupin,
    Mollusc,
}

impl std::str::FromStr for Allergenic {
    type Err = Error;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "(a1)" => Ok(Allergenic::Wheat),
            "(a2)" => Ok(Allergenic::Rye),
            "(a3)" => Ok(Allergenic::Barley),
            "(a4)" => Ok(Allergenic::Oat),
            "(a5)" => Ok(Allergenic::Spelt),
            "(a6)" => Ok(Allergenic::Kamut),
            "(b)" => Ok(Allergenic::Crustacean),
            "(c)" => Ok(Allergenic::Egg),
            "(d)" => Ok(Allergenic::Fish),
            "(e)" => Ok(Allergenic::Peanut),
            "(f)" => Ok(Allergenic::Soya),
            "(g)" => Ok(Allergenic::Lactose),
            "(h1)" => Ok(Allergenic::Almond),
            "(h2)" => Ok(Allergenic::Hazelnut),
            "(h3)" => Ok(Allergenic::Walnut),
            "(h4)" => Ok(Allergenic::Cashew),
            "(h5)" => Ok(Allergenic::PecanNut),
            "(h6)" => Ok(Allergenic::BrazilNut),
            "(h7)" => Ok(Allergenic::Pistachio),
            "(h8)" => Ok(Allergenic::MacadamiaNut),
            "(h9)" => Ok(Allergenic::QueenslandNut),
            "(i)" => Ok(Allergenic::Celery),
            "(j)" => Ok(Allergenic::Mustard),
            "(k)" => Ok(Allergenic::Sesame),
            "(l)" => Ok(Allergenic::Sulphite),
            "(m)" => Ok(Allergenic::Lupin),
            "(n)" => Ok(Allergenic::Mollusc),
            _ => Err(Error::InvalidIdentifier {
                kind: IdentifierKind::Allergenic,
                name: s.to_owned(),
            }),
        }
    }
}