From 3f22412aa31a2e82a615977b6a8c0da0b81a1aea Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Tue, 6 Mar 2018 18:48:08 +0100 Subject: [PATCH] Fix clippy warnings --- src/histogram.rs | 8 ++++---- src/minmax.rs | 8 ++------ src/moments/mod.rs | 5 +++++ src/traits.rs | 4 ++-- tests/histogram.rs | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/histogram.rs b/src/histogram.rs index deaaf45..d45d54d 100644 --- a/src/histogram.rs +++ b/src/histogram.rs @@ -33,12 +33,12 @@ macro_rules! define_histogram { pub fn with_const_width(start: f64, end: f64) -> Self { let step = (end - start) / (LEN as f64); let mut range = [0.; LEN + 1]; - for i in 0..(LEN + 1) { - range[i] = step * (i as f64); + for (i, r) in range.iter_mut().enumerate() { + *r = step * (i as f64); } Self { - range: range, + range, bin: [0; LEN], } } @@ -74,7 +74,7 @@ macro_rules! define_histogram { return Err(()); } Ok(Self { - range: range, + range, bin: [0; LEN], }) } diff --git a/src/minmax.rs b/src/minmax.rs index 2f30ec1..db1b609 100644 --- a/src/minmax.rs +++ b/src/minmax.rs @@ -33,9 +33,7 @@ impl Min { /// Create a new minium estimator from a given value. #[inline] pub fn from_value(x: f64) -> Min { - Min { - x: x, - } + Min { x } } /// Create a new minimum estimator. @@ -115,9 +113,7 @@ impl Max { /// Create a new maxium estimator from a given value. #[inline] pub fn from_value(x: f64) -> Max { - Max { - x: x, - } + Max { x } } /// Create a new maximum estimator. diff --git a/src/moments/mod.rs b/src/moments/mod.rs index eda328c..d05f1df 100644 --- a/src/moments/mod.rs +++ b/src/moments/mod.rs @@ -44,6 +44,11 @@ impl Moments { } } + #[inline] + pub fn is_empty(&self) -> bool { + self.n == 0 + } + #[inline] pub fn len(&self) -> u64 { self.n diff --git a/src/traits.rs b/src/traits.rs index ab53d53..4867f5c 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -21,12 +21,12 @@ pub trait Histogram: /// Return an iterator over the bins normalized by the bin widths. fn normalized_bins(&self) -> IterNormalized<<&Self as IntoIterator>::IntoIter> { - IterNormalized { histogram_iter: (&self).into_iter() } + IterNormalized { histogram_iter: self.into_iter() } } /// Return an iterator over the bin widths. fn widths(&self) -> IterWidths<<&Self as IntoIterator>::IntoIter> { - IterWidths { histogram_iter: (&self).into_iter() } + IterWidths { histogram_iter: self.into_iter() } } } diff --git a/tests/histogram.rs b/tests/histogram.rs index b4bbd15..1c4ac20 100644 --- a/tests/histogram.rs +++ b/tests/histogram.rs @@ -12,7 +12,7 @@ define_histogram!(Histogram10, 10); fn with_const_width() { let mut h = Histogram10::with_const_width(0., 100.); for i in 0..100 { - h.add(i as f64).unwrap(); + h.add(f64::from(i)).unwrap(); } assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]); }