From 6f0d9e991d5396c81d32a04dfd5d08ae755a977c Mon Sep 17 00:00:00 2001 From: Willaim Fleming Date: Thu, 6 Jul 2017 10:28:30 +0100 Subject: [PATCH] fixed step_by change #27741 --- src/lib.rs | 2 +- src/time_unit/mod.rs | 37 +++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index eaaac6b..433f259 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(feature="clippy", feature(plugin))] #![cfg_attr(feature="clippy", plugin(clippy))] #![feature(conservative_impl_trait)] -#![feature(step_by)] +#![feature(iterator_step_by)] extern crate chrono; extern crate nom; diff --git a/src/time_unit/mod.rs b/src/time_unit/mod.rs index 3bdf07e..77aff4d 100644 --- a/src/time_unit/mod.rs +++ b/src/time_unit/mod.rs @@ -40,8 +40,8 @@ pub trait TimeUnitField fn ordinal_from_name(name: &str) -> Result { bail!(ErrorKind::Expression(format!("The '{}' field does not support using names. '{}' \ specified.", - Self::name(), - name))) + Self::name(), + name))) } fn validate_ordinal(ordinal: Ordinal) -> Result { //println!("validate_ordinal for {} => {}", Self::name(), ordinal); @@ -49,15 +49,15 @@ pub trait TimeUnitField i if i < Self::inclusive_min() => { bail!(ErrorKind::Expression(format!("{} must be greater than or equal to {}. ('{}' \ specified.)", - Self::name(), - Self::inclusive_min(), - i))) + Self::name(), + Self::inclusive_min(), + i))) } i if i > Self::inclusive_max() => { bail!(ErrorKind::Expression(format!("{} must be less than {}. ('{}' specified.)", - Self::name(), - Self::inclusive_max(), - i))) + Self::name(), + Self::inclusive_max(), + i))) } i => Ok(i), } @@ -70,20 +70,25 @@ pub trait TimeUnitField All => Ok(Self::supported_ordinals()), Point(ordinal) => Ok((&[ordinal]).iter().cloned().collect()), NamedPoint(ref name) => { - Ok((&[Self::ordinal_from_name(name)?]).iter().cloned().collect()) + Ok((&[Self::ordinal_from_name(name)?]) + .iter() + .cloned() + .collect()) } Period(start, step) => { let start = Self::validate_ordinal(start)?; - Ok((start..Self::inclusive_max() + 1).step_by(step).collect()) + Ok((start..Self::inclusive_max() + 1) + .step_by(step as usize) + .collect()) } Range(start, end) => { match (Self::validate_ordinal(start), Self::validate_ordinal(end)) { (Ok(start), Ok(end)) if start <= end => Ok((start..end + 1).collect()), _ => { bail!(ErrorKind::Expression(format!("Invalid range for {}: {}-{}", - Self::name(), - start, - end))) + Self::name(), + start, + end))) } } } @@ -94,9 +99,9 @@ pub trait TimeUnitField (Ok(start), Ok(end)) if start <= end => Ok((start..end + 1).collect()), _ => { bail!(ErrorKind::Expression(format!("Invalid named range for {}: {}-{}", - Self::name(), - start_name, - end_name))) + Self::name(), + start_name, + end_name))) } } }