summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-09 16:15:00 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-12 18:06:49 +0200
commit2d24d60a27a28bf956b69b5b89db5a72d3e6ca90 (patch)
tree2b67a0e511c38d91f799c0b1a3ada41cdeee3d87
parent28013164e248d3217f7d8d19260e631c8cde02fc (diff)
Fix add/sub matching
-rw-r--r--src/timetype.rs9
1 files 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<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
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<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
.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<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
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<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
.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!(),
}
}