This commit is contained in:
aozhiwei 2021-12-10 00:06:45 +08:00
parent 0da572a5fa
commit 1d17503122
3 changed files with 41 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
*.lock

View File

@ -6,3 +6,7 @@ mod tests {
assert_eq!(result, 4);
}
}
mod xvalue;
pub use xvalue::XValue;

35
src/xvalue.rs Normal file
View File

@ -0,0 +1,35 @@
pub enum XValue<T> {
_IntVal(i64),
_UserData(T)
}
impl<T> XValue<T> {
pub fn new() -> Self {
return XValue::<T>::_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::<T>::_IntVal(0);
}
}
}
}