2017-04-03 14:51:39 -04:00
|
|
|
/* types/value.rs
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
use std::any::Any;
|
|
|
|
|
2017-04-03 16:27:09 -04:00
|
|
|
pub trait Value: Debug + ValueEq + IsBool + IsChar {
|
2017-04-03 14:51:39 -04:00
|
|
|
fn as_value(&self) -> &Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A trait on value types that makes it easier to compare values of disparate types. The methods
|
|
|
|
/// provided by this trait are used by the PartialEq implementation on Values.
|
|
|
|
pub trait ValueEq {
|
|
|
|
fn eq(&self, other: &Value) -> bool;
|
|
|
|
fn as_any(&self) -> &Any;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'lhs,'rhs> PartialEq<Value+'rhs> for Value+'lhs {
|
|
|
|
fn eq(&self, other: &(Value+'rhs)) -> bool {
|
|
|
|
ValueEq::eq(self, other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:27:09 -04:00
|
|
|
pub trait IsBool {
|
|
|
|
fn is_bool(&self) -> bool { false }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait IsChar {
|
|
|
|
fn is_char(&self) -> bool { false }
|
|
|
|
}
|