From 1d17503122c192d2135cb9be60eeacd7750c8768 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 10 Dec 2021 00:06:45 +0800 Subject: [PATCH] 1 --- .gitignore | 2 ++ src/lib.rs | 4 ++++ src/xvalue.rs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 .gitignore create mode 100644 src/xvalue.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1646c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target/ +*.lock \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1b4a90c..a1c3b5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,3 +6,7 @@ mod tests { assert_eq!(result, 4); } } + +mod xvalue; + +pub use xvalue::XValue; diff --git a/src/xvalue.rs b/src/xvalue.rs new file mode 100644 index 0000000..51bacea --- /dev/null +++ b/src/xvalue.rs @@ -0,0 +1,35 @@ +pub enum XValue { + _IntVal(i64), + _UserData(T) +} + + +impl XValue { + + pub fn new() -> Self { + return XValue::::_IntVal(0); + } + + pub fn get_i64(&self) -> i64 { + match self { + XValue::_IntVal(v) => { + return *v; + }, + XValue::_UserData(_v) => { + return 0; + } + } + } + + pub fn set_i64(&mut self, val: i64) { + match self { + XValue::_IntVal(v) => { + *v = val; + }, + XValue::_UserData(_v) => { + *self = XValue::::_IntVal(0); + } + } + } + +}