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
use sindra::Type;
use std::fmt;
#[derive(Copy, Debug, Clone, Hash, PartialEq)]
pub enum PType {
String,
Float,
Int,
Boolean,
Complex,
Set,
Void
}
impl Type for PType {
fn name(&self) -> &str {
match *self {
PType::String => "string",
PType::Float => "float",
PType::Int => "int",
PType::Boolean => "bool",
PType::Complex => "complex",
PType::Set => "set",
PType::Void => "void",
}
}
}
impl<'a> From<&'a str> for PType {
fn from(s: &'a str) -> PType {
match s {
"string" => PType::String,
"float" => PType::Float,
"int" => PType::Int,
"bool" => PType::Boolean,
"complex" => PType::Complex,
"set" => PType::Set,
_ => PType::Void,
}
}
}
impl fmt::Display for PType {
fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
write!(f, "{}", self.name())
}
}