Skip to content

Commit bfa8842

Browse files
committed
histogram/grid.rs: Minor improvement on styles, etc.
- Merged imports - By enabling `clippy::all` and `clippy::pedantic` lints, - Marked several methods as `must_use` - Found a redundant closue ( `Bins::len` is also more informative on the type than `|e| e.len()` )
1 parent 223ce08 commit bfa8842

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/histogram/grid.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::bins::Bins;
2-
use super::errors::BinsBuildError;
3-
use super::strategies::BinsBuildingStrategy;
1+
#![warn(clippy::all, clippy::pedantic)]
2+
3+
use super::{bins::Bins, errors::BinsBuildError, strategies::BinsBuildingStrategy};
44
use itertools::izip;
55
use ndarray::{ArrayBase, Axis, Data, Ix1, Ix2};
66
use std::ops::Range;
@@ -121,6 +121,7 @@ impl<A: Ord> Grid<A> {
121121
///
122122
/// assert_eq!(square_grid.ndim(), 2usize)
123123
/// ```
124+
#[must_use]
124125
pub fn ndim(&self) -> usize {
125126
self.projections.len()
126127
}
@@ -140,11 +141,13 @@ impl<A: Ord> Grid<A> {
140141
///
141142
/// assert_eq!(square_grid.shape(), vec![1usize, 2usize]);
142143
/// ```
144+
#[must_use]
143145
pub fn shape(&self) -> Vec<usize> {
144-
self.projections.iter().map(|e| e.len()).collect()
146+
self.projections.iter().map(Bins::len).collect()
145147
}
146148

147149
/// Returns the grid projections on each coordinate axis as a slice of immutable references.
150+
#[must_use]
148151
pub fn projections(&self) -> &[Bins<A>] {
149152
&self.projections
150153
}
@@ -266,6 +269,7 @@ impl<A: Ord + Clone> Grid<A> {
266269
/// vec![0..1, 3..4],
267270
/// );
268271
/// ```
272+
#[must_use]
269273
pub fn index(&self, index: &[usize]) -> Vec<Range<A>> {
270274
assert_eq!(
271275
index.len(),
@@ -311,6 +315,7 @@ impl<A: Ord + Clone> Grid<A> {
311315
/// [`Grid`]: struct.Grid.html
312316
/// [`histogram`]: trait.HistogramExt.html
313317
/// [`strategy`]: strategies/index.html
318+
#[allow(clippy::module_name_repetitions)]
314319
pub struct GridBuilder<B: BinsBuildingStrategy> {
315320
bin_builders: Vec<B>,
316321
}
@@ -357,6 +362,7 @@ where
357362
/// [`Grid`]: struct.Grid.html
358363
/// [`strategy`]: strategies/index.html
359364
/// [`from_array`]: #method.from_array.html
365+
#[must_use]
360366
pub fn build(&self) -> Grid<A> {
361367
let projections: Vec<_> = self.bin_builders.iter().map(|b| b.build()).collect();
362368
Grid::from(projections)

0 commit comments

Comments
 (0)