Skip to content

Commit f9dbb68

Browse files
committed
Fixes from Clippy
1 parent f9a076d commit f9dbb68

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

src/axis.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl TickSteps {
111111
let overflow = start_options[0] * 10.0;
112112
let curr = start_options
113113
.iter()
114-
.skip_while(|&step| step < &start)
115-
.next();
114+
.find(|&step| step >= &start);
116115

117116
TickSteps {
118117
next: *curr.unwrap_or(&overflow),
@@ -138,8 +137,7 @@ impl Iterator for TickSteps {
138137
let overflow = curr_steps[0] * 10.0;
139138
self.next = *curr_steps
140139
.iter()
141-
.skip_while(|&s| s <= &curr)
142-
.next()
140+
.find(|&s| s > &curr)
143141
.unwrap_or(&overflow);
144142
Some(curr)
145143
}
@@ -148,7 +146,7 @@ impl Iterator for TickSteps {
148146
fn generate_ticks(min: f64, max: f64, step_size: f64) -> Vec<f64> {
149147
// "fix" just makes sure there are no floating-point errors
150148
fn fix(x: f64) -> f64 {
151-
const PRECISION: f64 = 100000_f64;
149+
const PRECISION: f64 = 100_000_f64;
152150
(x * PRECISION).round() / PRECISION
153151
}
154152

@@ -203,8 +201,7 @@ fn calculate_tick_step_for_range(min: f64, max: f64, max_ticks: usize) -> f64 {
203201
let min_tick_step = range / max_ticks as f64;
204202
// Get the first entry which is our smallest possible tick step size
205203
let smallest_valid_step = TickSteps::start_at(min_tick_step)
206-
.skip_while(|&s| number_of_ticks(min, max, s) > max_ticks)
207-
.next()
204+
.find(|&s| number_of_ticks(min, max, s) <= max_ticks)
208205
.expect("ERROR: We've somehow run out of tick step options!");
209206
// Count how many ticks that relates to
210207
let actual_num_ticks = number_of_ticks(min, max, smallest_valid_step);

src/repr/boxplot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct BoxPlot<'a> {
3535
}
3636

3737
impl<'a> BoxPlot<'a> {
38-
pub fn from_slice(v: &'a [(f64)]) -> Self {
38+
pub fn from_slice(v: &'a [f64]) -> Self {
3939
BoxPlot {
4040
data: BoxData::Ref(v),
4141
style: BoxStyle::new(),

src/style.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl LineStyle {
3838
}
3939

4040
if let Some(ref v) = other.linejoin {
41-
self.linejoin = Some(v.clone())
41+
self.linejoin = Some(*v)
4242
}
4343
}
4444
pub fn colour<T>(mut self, value: T) -> Self
@@ -101,7 +101,7 @@ impl PointStyle {
101101

102102
pub fn overlay(&mut self, other: &Self) {
103103
if let Some(ref v) = other.marker {
104-
self.marker = Some(v.clone())
104+
self.marker = Some(*v)
105105
}
106106

107107
if let Some(ref v) = other.colour {

src/text_render.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn tick_offset_map(axis: &axis::ContinuousAxis, face_width: u32) -> HashMap<i32,
2929
/// Given a histogram object,
3030
/// the total scale of the axis
3131
/// and the number of face cells to work with,
32-
/// create a mapping of cell offset to bin bound
32+
/// return which cells will contain a bin bound
3333
fn bound_cell_offsets(
3434
hist: &repr::Histogram,
3535
x_axis: &axis::ContinuousAxis,
@@ -60,24 +60,24 @@ fn bins_for_cells(bound_cell_offsets: &[i32], face_width: u32) -> Vec<Option<i32
6060
}
6161
cell_bins.push(None); // end with an appended positive null
6262

63-
if *bins_cell_offset < 0 {
63+
if *bins_cell_offset <= 0 {
6464
cell_bins = cell_bins
6565
.iter()
6666
.skip(bins_cell_offset.wrapping_abs() as usize)
6767
.cloned()
6868
.collect();
69-
} else if *bins_cell_offset > 0 {
69+
} else {
7070
let mut new_bins = vec![None; (*bins_cell_offset) as usize];
7171
new_bins.extend(cell_bins.iter());
7272
cell_bins = new_bins;
7373
}
7474

75-
if cell_bins.len() < face_width as usize + 2 {
75+
if cell_bins.len() <= face_width as usize + 2 {
7676
let deficit = face_width as usize + 2 - cell_bins.len();
7777
let mut new_bins = cell_bins;
7878
new_bins.extend(vec![None; deficit].iter());
7979
cell_bins = new_bins;
80-
} else if cell_bins.len() > face_width as usize + 2 {
80+
} else {
8181
let new_bins = cell_bins;
8282
cell_bins = new_bins
8383
.iter()
@@ -429,7 +429,7 @@ pub fn overlay(under: &str, over: &str, x: i32, y: i32) -> String {
429429
let new_lines: Vec<String> = (0..lines_deficit)
430430
.map(|_| (0..over_width).map(|_| ' ').collect::<String>())
431431
.collect();
432-
let mut temp = split_over.clone();
432+
let mut temp = split_over;
433433
for new_line in new_lines {
434434
temp.push(new_line);
435435
}
@@ -616,7 +616,6 @@ mod tests {
616616

617617
#[test]
618618
fn test_render_face_points() {
619-
use crate::repr;
620619
use crate::style::PointStyle;
621620
let data = vec![
622621
(-3.0, 2.3),

src/utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn quartiles(s: &[f64]) -> (f64, f64, f64) {
3939
(median(a), median(&s), median(b))
4040
}
4141

42+
/// Given a slice of numbers, return the minimum and maximum values
4243
pub fn range(s: &[f64]) -> (f64, f64) {
4344
let mut min = f64::INFINITY;
4445
let mut max = f64::NEG_INFINITY;
@@ -49,9 +50,7 @@ pub fn range(s: &[f64]) -> (f64, f64) {
4950
(min, max)
5051
}
5152

52-
/**
53-
Floor or ceiling the min or max to zero to avoid them both having the same value
54-
*/
53+
/// Floor or ceiling the min or max to zero to avoid them both having the same value
5554
pub fn pad_range_to_zero(min: f64, max: f64) -> (f64, f64) {
5655
if (min - max).abs() < std::f64::EPSILON {
5756
(if min > 0. {0.} else {min}, if max < 0. {0.} else {max})

0 commit comments

Comments
 (0)