From 576b81e52c144b21d802ea9716281864385364e1 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 1 Sep 2018 08:33:45 -0700 Subject: [PATCH] [types] OMG SO MUCH LIFETIME NONSENSE --- types/src/number/integer.rs | 10 ++++++---- types/src/object.rs | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/types/src/number/integer.rs b/types/src/number/integer.rs index a11024b..ab725b7 100644 --- a/types/src/number/integer.rs +++ b/types/src/number/integer.rs @@ -17,16 +17,18 @@ impl Number for Int { } impl PartialEq for Int { - fn eq(&self, rhs: &Obj) -> bool { - match rhs.obj().and_then(Object::as_num) { + fn eq<'a>(&self, rhs: &'a Obj) -> bool { + let obj: Option<&'a Object> = rhs.obj(); + let num: Option<&'a Number> = obj.and_then(Object::as_num); + match num { Some(num) => self == num, None => false } } } -impl PartialEq for Int { - fn eq(&self, rhs: &Number) -> bool { +impl<'a> PartialEq for Int { + fn eq(&self, rhs: &(Number + 'a)) -> bool { match rhs.as_int() { Some(rhs) => *self == *rhs, None => false diff --git a/types/src/object.rs b/types/src/object.rs index 3eb2201..584421a 100644 --- a/types/src/object.rs +++ b/types/src/object.rs @@ -44,11 +44,11 @@ pub trait Object: } impl Obj { - pub fn new(obj: T) -> Obj { + pub fn new(obj: T) -> Obj { Obj::Ptr(Box::new(obj)) } - pub fn obj<'a>(&'a self) -> Option<&'a Object> { + pub fn obj<'s, 'r: 's>(&'s self) -> Option<&'r (Object + 's)> { match self { Obj::Ptr(obj) => Some(obj.deref()), Obj::Null => None @@ -60,7 +60,7 @@ impl Obj { mem::replace(self, Obj::Null) } - pub fn unbox_as(&self) -> Option<&T> { + pub fn unbox_as(&self) -> Option<&T> { match self { Obj::Null => None, Obj::Ptr(obj) => obj.as_any().downcast_ref::()