Break type checks into separate traits

This commit is contained in:
Eryn Wells 2017-04-09 14:08:54 -07:00
parent b094310b3c
commit 370083e2f0
3 changed files with 30 additions and 2 deletions

View file

@ -3,17 +3,22 @@
*/
use std::any::Any;
use super::value::*;
use value::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Bool(pub bool);
impl Value for Bool {
fn as_value(&self) -> &Value { self }
}
impl IsBool for Bool {
fn is_bool(&self) -> bool { true }
}
impl IsChar for Bool { }
impl IsNumber for Bool { }
impl ValueEq for Bool {
fn eq(&self, other: &Value) -> bool {
other.as_any().downcast_ref::<Self>().map_or(false, |x| x == self)