summaryrefslogtreecommitdiff
path: root/src/types.rs
blob: 6b0aacd484986273284c9010b8db9d507888fca4 (plain)
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
#[derive(Copy, Clone, Debug)]
pub enum Value {
    Boolean(bool),
    Unsigned(u32),
    Signed(i32),
    Floating(f64),
}

impl Value {
    pub fn from_bool(v: bool) -> Value {
        Value::Boolean(v)
    }
    pub fn from_unsigned(v: u32) -> Value {
        Value::Unsigned(v)
    }
    pub fn from_signed(v: i32) -> Value {
        Value::Signed(v)
    }
    pub fn from_floating(v: f64) -> Value {
        Value::Floating(v)
    }
}

impl From<bool> for Value {
    fn from(v: bool) -> Self {
        Value::from_bool(v)
    }
}

impl From<u8> for Value {
    fn from(v: u8) -> Self {
        Value::from_unsigned(v as u32)
    }
}

impl From<u16> for Value {
    fn from(v: u16) -> Self {
        Value::from_unsigned(v as u32)
    }
}

impl From<u32> for Value {
    fn from(v: u32) -> Self {
        Value::from_unsigned(v)
    }
}

impl From<i8> for Value {
    fn from(v: i8) -> Self {
        Value::from_signed(v as i32)
    }
}

impl From<i16> for Value {
    fn from(v: i16) -> Self {
        Value::from_signed(v as i32)
    }
}

impl From<i32> for Value {
    fn from(v: i32) -> Self {
        Value::from_signed(v)
    }
}

impl From<f64> for Value {
    fn from(v: f64) -> Self {
        Value::from_floating(v)
    }
}

#[derive(Clone, Debug)]
pub struct NamedValue {
    name: String,
    value: Option<Value>,
}

impl NamedValue {
    pub fn new(name: &str, value: Option<Value>) -> NamedValue {
        NamedValue {
            name: name.into(),
            value: value,
        }
    }

    pub fn get_value(&self) -> Option<Value> {
        self.value
    }
}