Initial stack typing
This commit is contained in:
30
src/value.rs
Normal file
30
src/value.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use Result;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum Value {
|
||||
Int(i32),
|
||||
HeapRef(usize),
|
||||
}
|
||||
|
||||
impl TryInto<i32> for Value {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_into(self) -> Result<i32> {
|
||||
match self {
|
||||
Value::Int(a) => Ok(a),
|
||||
Value::HeapRef(_) => Err("Cannot use HeapRef as i32"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<i32> for &Value {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_into(self) -> Result<i32> {
|
||||
match self {
|
||||
&Value::Int(a) => Ok(a),
|
||||
&Value::HeapRef(_) => Err("Cannot use HeapRef as i32"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user