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
pub mod err;


pub use self::err::{PartError, Result};
use std::fmt;

#[repr(u32)]
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum Part {
    /// Symbol '_'.
    None = 0x5f,
    /// Symbol 'a'.
    ArmLeft = 0x61,
    /// Symbol 'A'.
    ArmRight = 0x41,
    /// Symbol 'b'.
    Boobs = 0x62,
    /// Symbol 'c'.
    Clavicle = 0x63,
    /// Symbol 'e'.
    EarLeft = 0x65,
    /// Symbol 'E'.
    EarRight = 0x45,
    /// Symbol 'y'.
    EyeLeft = 0x79,
    /// Symbol 'Y'.
    EyeRight = 0x59,
    /// Symbol 'o'.
    HairTop = 0x6f,
    /// Symbol 'r'.
    HairLeft = 0x72,
    /// Symbol 'R'.
    HairRight = 0x52,
    /// Symbol 'd',
    HandLeft = 0x64,
    /// Symbol 'D',
    HandRight = 0x44,
    /// Symbol 'm',
    Mouth = 0x6d,
    /// Symbol 't'.
    Tail = 0x74,
    /// Symbol 'l'.
    Bell = 0x6c,
    /// Symbol 'x'.
    ExclamationMark = 0x78,
    /// Symbol 'X'.
    ExclamationMarks = 0x58,
    /// Symbol 'h'.
    Heart = 0x68,
    /// Symbol 'H'.
    Hearts = 0x48,
    /// Symbol 'n'.
    Lantern = 0x6e,
    /// Symbol 'q'.
    QuestionMark = 0x71,
    /// Symbol 'Q'.
    QuestionMarks = 0x51,
    /// Symbol 'w'.
    WoolBall = 0x77,
}

impl Part {
    pub fn new(part: &str) -> Result<Self> {
        match part {
            "ArmLeft" => Ok(Part::ArmLeft),
            "ArmRight" => Ok(Part::ArmRight),
            "Boobs" => Ok(Part::Boobs),
            "Clavicle" => Ok(Part::Clavicle),
            "EarLeft" => Ok(Part::EarLeft),
            "EarRight" => Ok(Part::EarRight),
            "EyeLeft" => Ok(Part::EyeLeft),
            "EyeRight" => Ok(Part::EyeRight),
            "HairTop" => Ok(Part::HairTop),
            "HairLeft" => Ok(Part::HairLeft),
            "HairRight" => Ok(Part::HairRight),
            "HandLeft" => Ok(Part::HandLeft),
            "HandRight" => Ok(Part::HandRight),
            "Mouth" => Ok(Part::Mouth),
            "Tail" => Ok(Part::Tail),

            "Bell" => Ok(Part::Bell),
            "ExclamationMark" => Ok(Part::ExclamationMark),
            "ExclamationMarks" => Ok(Part::ExclamationMarks),
            "Heart" => Ok(Part::Heart),
            "Hearts" => Ok(Part::Hearts),
            "Lantern" => Ok(Part::Lantern),
            "QuestionMark" => Ok(Part::QuestionMark),
            "QuestionMarks" => Ok(Part::QuestionMarks),
            "WoolBall" => Ok(Part::WoolBall),

            "None" => Ok(Part::None),
            name => Err(PartError::UnknownPart(name.to_string())),
        }
    }

    pub fn not_empty(&self) -> Option<&Part> {
        match *self {
            Part::None => None,
            ref other => Some(other)
        }
    }
}

impl fmt::Display for Part {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", match *self {
              Part::ArmLeft => "Ml",
              Part::ArmRight => "Mr",
              Part::Boobs => "Oo",
              Part::Clavicle => "Cl",
              Part::EarLeft => "Al",
              Part::EarRight => "Ar",
              Part::EyeLeft => "El",
              Part::EyeRight => "Er",
              Part::HairTop => "Rt",
              Part::HairLeft => "Rl",
              Part::HairRight => "Rr",
              Part::HandLeft => "Hl",
              Part::HandRight => "Hr",
              Part::Mouth => "Mo",
              Part::Tail => "Ta",

              Part::Bell => "Be",
              Part::ExclamationMark => "Xm",
              Part::ExclamationMarks => "Xs",
              Part::Heart => "He",
              Part::Hearts => "Hs",
              Part::Lantern => "La",
              Part::QuestionMark => "Qm",
              Part::QuestionMarks => "Qs",
              Part::WoolBall => "Wb",

              Part::None => "__",
       })
    }
}

impl Default for Part {
    fn default() -> Part {
        Part::None
    }
}