From 2d24d60a27a28bf956b69b5b89db5a72d3e6ca90 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 9 Sep 2017 16:15:00 +0200 Subject: Fix add/sub matching --- src/timetype.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/timetype.rs b/src/timetype.rs index 014139b..b7391c8 100644 --- a/src/timetype.rs +++ b/src/timetype.rs @@ -334,6 +334,9 @@ fn add(a: Box, b: Box) -> Result { use timetype::TimeType as TT; match (*a, *b) { + (TT::Moment(mom), thing) => add_to_moment(mom, thing), + (thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotAdd(thing, TT::Moment(mom)))), + (TT::Seconds(a), other) => add_to_seconds(a, other), (other, TT::Seconds(a)) => add_to_seconds(a, other), @@ -365,8 +368,6 @@ fn add(a: Box, b: Box) -> Result { .map(Box::new) .and_then(|bx| add(Box::new(other), bx)) .and_then(|rx| sub(Box::new(rx), b)), - (thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotAdd(thing, TT::Moment(mom)))), - (TT::Moment(mom), thing) => add_to_moment(mom, thing), others => unimplemented!(), } } @@ -505,6 +506,9 @@ fn sub(a: Box, b: Box) -> Result { use timetype::TimeType as TT; match (*a, *b) { + (TT::Moment(mom), thing) => sub_from_moment(mom, thing), + (thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotSub(thing, TT::Moment(mom)))), + (TT::Seconds(a), other) => sub_from_seconds(a, other), (other, TT::Seconds(a)) => sub_from_seconds(a, other), @@ -536,7 +540,6 @@ fn sub(a: Box, b: Box) -> Result { .map(Box::new) .and_then(|bx| sub(Box::new(other), bx)) .and_then(|rx| add(Box::new(rx), b)), - (thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotSub(thing, TT::Moment(mom)))), others => unimplemented!(), } } -- cgit v1.2.3