use Result; use std::convert::TryInto; use heap::Heap; #[derive(Debug, Clone, PartialEq)] pub enum Value { Int(i32), HeapRef(Heap), } impl TryInto for Value { type Error = &'static str; fn try_into(self) -> Result { match self { Value::Int(a) => Ok(a), Value::HeapRef(_) => Err("Cannot use HeapRef as i32"), } } } impl TryInto for &Value { type Error = &'static str; fn try_into(self) -> Result { match *self { Value::Int(a) => Ok(a), Value::HeapRef(_) => Err("Cannot use HeapRef as i32"), } } }