summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-12 21:17:08 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-12 21:17:08 +0100
commit3954dd3ff48a3d82913506757917cb263616e3cc (patch)
treed517171a54a03b22ffc504dfb92ddb320b0943e5
parent3fa8d32f301c97306dd72a03fcd3d6e2bdda68ef (diff)
downloadcanopied-3954dd3ff48a3d82913506757917cb263616e3cc.tar.bz2
Add RawHex and display
-rw-r--r--src/types.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/types.rs b/src/types.rs
index f815b16..7403c62 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,9 +1,12 @@
+use std::fmt::{Display, Error, Formatter};
+
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Value {
Boolean(bool),
Unsigned(u32),
Signed(i32),
Floating(f64),
+ RawHex(u8),
}
impl Value {
@@ -19,6 +22,21 @@ impl Value {
pub fn from_floating(v: f64) -> Value {
Value::Floating(v)
}
+ pub fn from_raw(v: u8) -> Value {
+ Value::RawHex(v)
+ }
+}
+
+impl Display for Value {
+ fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
+ match *self {
+ Value::Boolean(b) => write!(f, "b:{}", b),
+ Value::Unsigned(u) => write!(f, "u:{}", u),
+ Value::Signed(s) => write!(f, "s:{}", s),
+ Value::Floating(v) => write!(f, "f:{}", v),
+ Value::RawHex(h) => write!(f, "r:{:02X}", h),
+ }
+ }
}
impl From<bool> for Value {