From 1a3b7adc5ab24b5f02111322031800b81deb6a13 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 25 Aug 2018 09:21:51 -0700 Subject: [PATCH] [types] Clean up Object a little, add default implementations --- types/src/object.rs | 7 +++++-- types/src/pair.rs | 1 - types/src/sym.rs | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/types/src/object.rs b/types/src/object.rs index d25df2e..3c9baf3 100644 --- a/types/src/object.rs +++ b/types/src/object.rs @@ -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 { diff --git a/types/src/pair.rs b/types/src/pair.rs index ecb4c46..b142c25 100644 --- a/types/src/pair.rs +++ b/types/src/pair.rs @@ -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 { diff --git a/types/src/sym.rs b/types/src/sym.rs index a502d5c..3c47599 100644 --- a/types/src/sym.rs +++ b/types/src/sym.rs @@ -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) } }