summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-02 16:18:23 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-02 16:18:23 +0200
commit4cdddaae8de1a49702b74d661057682596359d90 (patch)
tree31870ab4e5007c7a137d29a03c93038f5fb9fbf2
parent75f2448d85316ea8e03248592d209549d9ba6ed3 (diff)
Impl error catching if point in time is added/subtracted
-rw-r--r--Cargo.toml2
-rw-r--r--src/timetype.rs5
2 files changed, 6 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index df52aa2..17b7e02 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,4 +14,4 @@ repository = "https://github.com/matthiasbeyer/kairos"
[dependencies]
chrono = "0.4"
-error-chain = "0.3"
+error-chain = "0.10"
diff --git a/src/timetype.rs b/src/timetype.rs
index 3ac88f2..3541d76 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -7,6 +7,9 @@ use std::ops::Add;
use std::ops::Sub;
use result::Result;
+use error::KairosErrorKind as KEK;
+use error::KairosError as KE;
+use error_chain::ChainedError;
/// A Type of Time, currently based on chrono::NaiveDateTime
#[derive(Debug)]
@@ -71,6 +74,7 @@ fn add(a: Box<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
(other, TT::Addition(a, b)) => add(a, b)
.map(Box::new)
.and_then(|bx| add(Box::new(other), bx)),
+ (thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotAdd(thing, TT::Moment(mom)))),
others => unimplemented!(),
}
}
@@ -92,6 +96,7 @@ fn sub(a: Box<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
(other, TT::Subtraction(a, b)) => sub(a, b)
.map(Box::new)
.and_then(|bx| sub(Box::new(other), bx)),
+ (thing, TT::Moment(mom)) => Err(KE::from_kind(KEK::CannotSub(thing, TT::Moment(mom)))),
others => unimplemented!(),
}
}