summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/types.rs b/src/types.rs
new file mode 100644
index 0000000..6b0aacd
--- /dev/null
+++ b/src/types.rs
@@ -0,0 +1,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
+ }
+}