32 lines
633 B
Rust
32 lines
633 B
Rust
use Result;
|
|
use std::convert::TryInto;
|
|
use heap::Heap;
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub enum Value {
|
|
Int(i32),
|
|
HeapRef(Heap),
|
|
}
|
|
|
|
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"),
|
|
}
|
|
}
|
|
}
|