Skip to content

Commit fdd65bf

Browse files
authored
clippy lints (#95)
1 parent 79be19f commit fdd65bf

File tree

9 files changed

+37
-29
lines changed

9 files changed

+37
-29
lines changed

plotly/examples/scientific_charts.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use std::f64::consts::PI;
2+
13
use plotly::common::{ColorScale, ColorScalePalette, Title};
24
use plotly::contour::Contours;
35
use plotly::{Contour, HeatMap, Layout, Plot};
4-
use std::f64::consts::PI;
56

67
// Contour Plots
78
fn simple_contour_plot(show: bool) {
@@ -16,16 +17,15 @@ fn simple_contour_plot(show: bool) {
1617
y.push(value);
1718
}
1819

19-
for xi in 0..n {
20+
x.iter().take(n).for_each(|x| {
2021
let mut row = Vec::<f64>::new();
21-
for yi in 0..n {
22-
let radius_squared = x[xi].powf(2.0) + y[yi].powf(2.0);
23-
let zv =
24-
x[xi].sin() * y[yi].cos() * radius_squared.sin() / (radius_squared + 1.0).log10();
22+
y.iter().take(n).for_each(|y| {
23+
let radius_squared = x.powf(2.0) + y.powf(2.0);
24+
let zv = x.sin() * y.cos() * radius_squared.sin() / (radius_squared + 1.0).log10();
2525
row.push(zv);
26-
}
26+
});
2727
z.push(row);
28-
}
28+
});
2929

3030
let trace = Contour::new(x, y, z);
3131
let mut plot = Plot::new();

plotly/src/common/color.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ impl Color for String {}
3030
impl Color for Rgb {}
3131
impl Color for Rgba {}
3232

33-
/// ColorArray is only used internally to provide a helper method for converting Vec<impl Color2> to
34-
/// Vec<Box<dyn Color2>>, as we would otherwise fall foul of the orphan rules.
33+
/// ColorArray is only used internally to provide a helper method for converting Vec<impl Color> to
34+
/// Vec<Box<dyn Color>>, as we would otherwise fall foul of the orphan rules.
3535
pub(crate) struct ColorArray<C: Color>(pub(crate) Vec<C>);
3636

37+
#[allow(clippy::from_over_into)]
3738
impl<C: Color> Into<Vec<Box<dyn Color>>> for ColorArray<C> {
3839
fn into(self) -> Vec<Box<dyn Color>> {
3940
self.0

plotly/src/common/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ where
187187
Vector(Vec<T>),
188188
}
189189

190-
#[derive(Serialize, Clone, Debug, PartialEq)]
190+
#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
191191
#[serde(rename_all = "lowercase")]
192192
pub enum PlotType {
193193
Scatter,

plotly/src/layout/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2328,12 +2328,14 @@ impl Template {
23282328
}
23292329
}
23302330

2331+
#[allow(clippy::from_over_into)]
23312332
impl Into<Cow<'static, Template>> for Template {
23322333
fn into(self) -> Cow<'static, Template> {
23332334
Cow::Owned(self)
23342335
}
23352336
}
23362337

2338+
#[allow(clippy::from_over_into)]
23372339
impl Into<Cow<'static, Template>> for &'static Template {
23382340
fn into(self) -> Cow<'static, Template> {
23392341
Cow::Borrowed(self)

plotly/src/layout/themes.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use crate::{
77

88
pub static DEFAULT: Lazy<Template> = Lazy::new(|| {
99
let layout_template = LayoutTemplate::new();
10-
let template = Template::new().layout(layout_template);
11-
template
10+
Template::new().layout(layout_template)
1211
});
1312

1413
pub static PLOTLY_WHITE: Lazy<Template> = Lazy::new(|| {
@@ -82,8 +81,7 @@ pub static PLOTLY_WHITE: Lazy<Template> = Lazy::new(|| {
8281
.zero_line_color("#EBF0F8")
8382
.zero_line_width(2),
8483
);
85-
let template = Template::new().layout(layout_template);
86-
template
84+
Template::new().layout(layout_template)
8785
});
8886

8987
pub static PLOTLY_DARK: Lazy<Template> = Lazy::new(|| {
@@ -159,8 +157,7 @@ pub static PLOTLY_DARK: Lazy<Template> = Lazy::new(|| {
159157
.zero_line_color("#283442")
160158
.zero_line_width(2),
161159
);
162-
let template = Template::new().layout(layout_template);
163-
template
160+
Template::new().layout(layout_template)
164161
});
165162

166163
#[cfg(test)]

plotly/src/ndarray.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[derive(PartialOrd, PartialEq)]
1+
#[derive(PartialOrd, PartialEq, Eq)]
22
pub enum ArrayTraces {
33
OverColumns,
44
OverRows,

plotly/src/plot.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use std::fs::File;
2+
use std::io::Write;
3+
use std::path::Path;
4+
15
use askama::Template;
26
use dyn_clone::DynClone;
37
use erased_serde::Serialize as ErasedSerialize;
@@ -6,9 +10,6 @@ use rand::{
610
thread_rng,
711
};
812
use serde::Serialize;
9-
use std::fs::File;
10-
use std::io::Write;
11-
use std::path::Path;
1213

1314
use crate::{Configuration, Layout};
1415

@@ -122,6 +123,10 @@ impl Traces {
122123
self.traces.len()
123124
}
124125

126+
pub fn is_empty(&self) -> bool {
127+
self.traces.is_empty()
128+
}
129+
125130
pub fn iter(&self) -> std::slice::Iter<'_, Box<dyn Trace>> {
126131
self.traces.iter()
127132
}
@@ -466,9 +471,10 @@ impl PartialEq for Plot {
466471

467472
#[cfg(test)]
468473
mod tests {
469-
use serde_json::{json, to_value};
470474
use std::path::PathBuf;
471475

476+
use serde_json::{json, to_value};
477+
472478
use super::*;
473479
use crate::Scatter;
474480

plotly/src/private.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
#[cfg(feature = "plotly_ndarray")]
2+
use ndarray::{Array, Ix2};
13
use serde::Serialize;
24

35
#[cfg(feature = "plotly_ndarray")]
46
use crate::ndarray::ArrayTraces;
5-
#[cfg(feature = "plotly_ndarray")]
6-
use ndarray::{Array, Ix2};
77

88
pub fn owned_string_vector<S: AsRef<str>>(s: Vec<S>) -> Vec<String> {
99
s.iter()
@@ -159,13 +159,13 @@ mod tests {
159159
let x: NumOrString = 100.0_f32.into();
160160
assert_eq!(x, NumOrString::F(100.));
161161

162-
let x: NumOrString = (-100 as isize).into();
162+
let x: NumOrString = (-100_isize).into();
163163
assert_eq!(x, NumOrString::I(-100));
164164

165-
let x: NumOrString = (-100 as i64).into();
165+
let x: NumOrString = (-100_i64).into();
166166
assert_eq!(x, NumOrString::I(-100));
167167

168-
let x: NumOrString = (-100 as i32).into();
168+
let x: NumOrString = (-100_i32).into();
169169
assert_eq!(x, NumOrString::I(-100));
170170

171171
let x: NumOrString = 100_usize.into();

plotly_kaleido/build.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
extern crate directories;
22
extern crate zip;
3-
use directories::ProjectDirs;
3+
44
use std::env;
55
use std::fs;
66
use std::io;
77
use std::io::Result;
88
use std::path::{Path, PathBuf};
99
use std::process::Command;
1010

11+
use directories::ProjectDirs;
12+
1113
#[cfg(target_os = "linux")]
1214
const KALEIDO_URL: &str =
1315
"https://github.com/plotly/Kaleido/releases/download/v0.2.1/kaleido_linux_x64.zip";
@@ -50,7 +52,7 @@ fn extract_zip(p: &Path, zip_file: &Path) -> Result<()> {
5052
}
5153
}
5254

53-
if (&*file.name()).ends_with('/') {
55+
if (file.name()).ends_with('/') {
5456
println!(
5557
"File {} extracted to \"{}\"",
5658
i,

0 commit comments

Comments
 (0)