summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-03-05 19:51:13 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-03-05 19:51:13 +0100
commit2a75e24c9834b2f4599e0b310454a72e0b59debb (patch)
tree1f9098e96e80292a5b8bba0ef856906141f3b482
parent07f108e1d25da387735ce2ddca04a768a2739d9f (diff)
downloadkairos-2a75e24c9834b2f4599e0b310454a72e0b59debb.tar.gz
kairos-2a75e24c9834b2f4599e0b310454a72e0b59debb.tar.xz
Replace try!() with ? operator
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/parser/iterator.rs10
-rw-r--r--src/timetype.rs66
2 files changed, 38 insertions, 38 deletions
diff --git a/src/parser/iterator.rs b/src/parser/iterator.rs
index 8661646..be814b0 100644
--- a/src/parser/iterator.rs
+++ b/src/parser/iterator.rs
@@ -91,7 +91,7 @@ impl Iterator {
Iterspec::Yearly => unit_to_amount(1, Unit::Year),
};
- let into_ndt = |e: timetype::TimeType| try!(e.calculate())
+ let into_ndt = |e: timetype::TimeType| e.calculate()?
.get_moment()
.ok_or(Error::NotADateInsideIterator)
.map_err(Error::from)
@@ -99,22 +99,22 @@ impl Iterator {
match self.2 {
Some(UntilSpec::Exact(e)) => {
- let base = try!(into_ndt(self.0.into_timetype()?));
- let e = try!(into_ndt(e.into_timetype()?));
+ let base = into_ndt(self.0.into_timetype()?)?;
+ let e = into_ndt(e.into_timetype()?)?;
iter::Iter::build(base, recur)
.map(|it| UserIterator::UntilIterator(it.until(e)))
},
Some(UntilSpec::Times(i)) => {
- let base = try!(into_ndt(self.0.into_timetype()?));
+ let base = into_ndt(self.0.into_timetype()?)?;
iter::Iter::build(base, recur)
.map(|it| it.times(i))
.map(UserIterator::TimesIter)
},
None => {
- let base = try!(into_ndt(self.0.into_timetype()?));
+ let base = into_ndt(self.0.into_timetype()?)?;
iter::Iter::build(base, recur)
.map(UserIterator::Iterator)
},
diff --git a/src/timetype.rs b/src/timetype.rs
index e49a5ea..8fdd1d1 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -472,7 +472,7 @@ fn do_calculate(tt: TimeType) -> Result<TimeType> {
fn end_of_year(tt: TimeType) -> Result<TimeType> {
use timetype::TimeType as TT;
- match try!(do_calculate(tt)) {
+ match do_calculate(tt)? {
els @ TT::Seconds(_) |
els @ TT::Minutes(_) |
els @ TT::Hours(_) |
@@ -502,7 +502,7 @@ fn end_of_year(tt: TimeType) -> Result<TimeType> {
fn end_of_month(tt: TimeType) -> Result<TimeType> {
use timetype::TimeType as TT;
- match try!(do_calculate(tt)) {
+ match do_calculate(tt)? {
els @ TT::Seconds(_) |
els @ TT::Minutes(_) |
els @ TT::Hours(_) |
@@ -534,7 +534,7 @@ fn end_of_month(tt: TimeType) -> Result<TimeType> {
fn end_of_day(tt: TimeType) -> Result<TimeType> {
use timetype::TimeType as TT;
- match try!(do_calculate(tt)) {
+ match do_calculate(tt)? {
els @ TT::Seconds(_) |
els @ TT::Minutes(_) |
els @ TT::Hours(_) |
@@ -563,7 +563,7 @@ fn end_of_day(tt: TimeType) -> Result<TimeType> {
fn end_of_hour(tt: TimeType) -> Result<TimeType> {
use timetype::TimeType as TT;
- match try!(do_calculate(tt)) {
+ match do_calculate(tt)? {
els @ TT::Seconds(_) |
els @ TT::Minutes(_) |
els @ TT::Hours(_) |
@@ -592,7 +592,7 @@ fn end_of_hour(tt: TimeType) -> Result<TimeType> {
fn end_of_minute(tt: TimeType) -> Result<TimeType> {
use timetype::TimeType as TT;
- match try!(do_calculate(tt)) {
+ match do_calculate(tt)? {
els @ TT::Seconds(_) |
els @ TT::Minutes(_) |
els @ TT::Hours(_) |
@@ -676,8 +676,8 @@ fn add_to_seconds(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Seconds(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => add_to_seconds(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => add_to_seconds(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => add_to_seconds(amount, add(b, c)?),
+ TT::Subtraction(b, c) => add_to_seconds(amount, sub(b, c)?),
}
}
@@ -697,8 +697,8 @@ fn add_to_minutes(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Minutes(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => add_to_minutes(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => add_to_minutes(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => add_to_minutes(amount, add(b, c)?),
+ TT::Subtraction(b, c) => add_to_minutes(amount, sub(b, c)?),
}
}
@@ -718,8 +718,8 @@ fn add_to_hours(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Hours(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => add_to_hours(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => add_to_hours(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => add_to_hours(amount, add(b, c)?),
+ TT::Subtraction(b, c) => add_to_hours(amount, sub(b, c)?),
}
}
@@ -739,8 +739,8 @@ fn add_to_days(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Days(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => add_to_days(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => add_to_days(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => add_to_days(amount, add(b, c)?),
+ TT::Subtraction(b, c) => add_to_days(amount, sub(b, c)?),
}
}
@@ -760,8 +760,8 @@ fn add_to_months(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Months(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => add_to_months(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => add_to_months(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => add_to_months(amount, add(b, c)?),
+ TT::Subtraction(b, c) => add_to_months(amount, sub(b, c)?),
}
}
@@ -781,8 +781,8 @@ fn add_to_years(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Years(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => add_to_years(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => add_to_years(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => add_to_years(amount, add(b, c)?),
+ TT::Subtraction(b, c) => add_to_years(amount, sub(b, c)?),
}
}
@@ -892,8 +892,8 @@ fn add_to_moment(mom: NaiveDateTime, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotAdd(TT::Moment(mom), TT::EndOfMinute(e))),
- TT::Addition(a, b) => add_to_moment(mom, try!(add(a, b))),
- TT::Subtraction(a, b) => add_to_moment(mom, try!(sub(a, b))),
+ TT::Addition(a, b) => add_to_moment(mom, add(a, b)?),
+ TT::Subtraction(a, b) => add_to_moment(mom, sub(a, b)?),
}
}
@@ -957,8 +957,8 @@ fn sub_from_seconds(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Seconds(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => sub_from_seconds(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => sub_from_seconds(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => sub_from_seconds(amount, add(b, c)?),
+ TT::Subtraction(b, c) => sub_from_seconds(amount, sub(b, c)?),
}
}
@@ -978,8 +978,8 @@ fn sub_from_minutes(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Minutes(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => sub_from_minutes(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => sub_from_minutes(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => sub_from_minutes(amount, add(b, c)?),
+ TT::Subtraction(b, c) => sub_from_minutes(amount, sub(b, c)?),
}
}
@@ -999,8 +999,8 @@ fn sub_from_hours(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Hours(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => sub_from_hours(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => sub_from_hours(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => sub_from_hours(amount, add(b, c)?),
+ TT::Subtraction(b, c) => sub_from_hours(amount, sub(b, c)?),
}
}
@@ -1020,8 +1020,8 @@ fn sub_from_days(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Days(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => sub_from_days(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => sub_from_days(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => sub_from_days(amount, add(b, c)?),
+ TT::Subtraction(b, c) => sub_from_days(amount, sub(b, c)?),
}
}
@@ -1041,8 +1041,8 @@ fn sub_from_months(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Months(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => sub_from_months(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => sub_from_months(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => sub_from_months(amount, add(b, c)?),
+ TT::Subtraction(b, c) => sub_from_months(amount, sub(b, c)?),
}
}
@@ -1062,8 +1062,8 @@ fn sub_from_years(amount: i64, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Years(amount), TT::EndOfMinute(e))),
- TT::Addition(b, c) => sub_from_years(amount, try!(add(b, c))),
- TT::Subtraction(b, c) => sub_from_years(amount, try!(sub(b, c))),
+ TT::Addition(b, c) => sub_from_years(amount, add(b, c)?),
+ TT::Subtraction(b, c) => sub_from_years(amount, sub(b, c)?),
}
}
@@ -1173,8 +1173,8 @@ fn sub_from_moment(mom: NaiveDateTime, tt: TimeType) -> Result<TimeType> {
TT::EndOfDay(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfDay(e))),
TT::EndOfHour(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfHour(e))),
TT::EndOfMinute(e) => Err(Error::CannotSub(TT::Moment(mom), TT::EndOfMinute(e))),
- TT::Addition(a, b) => sub_from_moment(mom, try!(add(a, b))),
- TT::Subtraction(a, b) => sub_from_moment(mom, try!(sub(a, b))),
+ TT::Addition(a, b) => sub_from_moment(mom, add(a, b)?),
+ TT::Subtraction(a, b) => sub_from_moment(mom, sub(a, b)?),
}
}