[types] Clean up Object a little, add default implementations

This commit is contained in:
Eryn Wells 2018-08-25 09:21:51 -07:00
parent 31081ba5a9
commit 1a3b7adc5a
3 changed files with 5 additions and 4 deletions

View file

@ -28,9 +28,12 @@ pub trait Object:
fmt::Debug + fmt::Debug +
fmt::Display fmt::Display
{ {
/// Cast this Object to an Any.
fn as_any(&self) -> &Any; fn as_any(&self) -> &Any;
fn as_pair(&self) -> Option<&Pair>; /// Cast this Object to a Pair if possible.
fn as_sym(&self) -> Option<&Sym>; fn as_pair(&self) -> Option<&Pair> { None }
/// Cast this Object to a Sym if possible.
fn as_sym(&self) -> Option<&Sym> { None }
} }
impl Obj { impl Obj {

View file

@ -43,7 +43,6 @@ impl Pair {
impl Object for Pair { impl Object for Pair {
fn as_any(&self) -> &Any { self } fn as_any(&self) -> &Any { self }
fn as_pair(&self) -> Option<&Pair> { Some(self) } fn as_pair(&self) -> Option<&Pair> { Some(self) }
fn as_sym(&self) -> Option<&Sym> { None }
} }
impl fmt::Display for Pair { impl fmt::Display for Pair {

View file

@ -24,7 +24,6 @@ impl Sym {
impl Object for Sym { impl Object for Sym {
fn as_any(&self) -> &Any { self } fn as_any(&self) -> &Any { self }
fn as_pair(&self) -> Option<&Pair> { None }
fn as_sym(&self) -> Option<&Sym> { Some(self) } fn as_sym(&self) -> Option<&Sym> { Some(self) }
} }