[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::Display
{
/// Cast this Object to an Any.
fn as_any(&self) -> &Any;
fn as_pair(&self) -> Option<&Pair>;
fn as_sym(&self) -> Option<&Sym>;
/// Cast this Object to a Pair if possible.
fn as_pair(&self) -> Option<&Pair> { None }
/// Cast this Object to a Sym if possible.
fn as_sym(&self) -> Option<&Sym> { None }
}
impl Obj {

View file

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

View file

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