Skip to content

Commit eea5070

Browse files
committed
fix clippy for examples
1 parent fd88b36 commit eea5070

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

examples/cpu-monitor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl Chart<Message> for CpuUsageChart {
292292
.front()
293293
.unwrap_or(&(
294294
chrono::DateTime::from_utc(
295-
chrono::NaiveDateTime::from_timestamp(0, 0),
295+
chrono::NaiveDateTime::from_timestamp_opt(0, 0).unwrap(),
296296
chrono::Utc,
297297
),
298298
0,
@@ -308,9 +308,9 @@ impl Chart<Message> for CpuUsageChart {
308308

309309
chart
310310
.configure_mesh()
311-
.bold_line_style(&plotters::style::colors::BLUE.mix(0.1))
312-
.light_line_style(&plotters::style::colors::BLUE.mix(0.05))
313-
.axis_style(ShapeStyle::from(&plotters::style::colors::BLUE.mix(0.45)).stroke_width(1))
311+
.bold_line_style(plotters::style::colors::BLUE.mix(0.1))
312+
.light_line_style(plotters::style::colors::BLUE.mix(0.05))
313+
.axis_style(ShapeStyle::from(plotters::style::colors::BLUE.mix(0.45)).stroke_width(1))
314314
.y_labels(10)
315315
.y_label_style(
316316
("sans-serif", 15)
@@ -327,9 +327,9 @@ impl Chart<Message> for CpuUsageChart {
327327
AreaSeries::new(
328328
self.data_points.iter().map(|x| (x.0, x.1 as i32)),
329329
0,
330-
&PLOT_LINE_COLOR.mix(0.175),
330+
PLOT_LINE_COLOR.mix(0.175),
331331
)
332-
.border_style(ShapeStyle::from(&PLOT_LINE_COLOR).stroke_width(2)),
332+
.border_style(ShapeStyle::from(PLOT_LINE_COLOR).stroke_width(2)),
333333
)
334334
.expect("failed to draw chart data");
335335
}

examples/large-data.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ impl Chart<Message> for ExampleChart {
210210

211211
chart
212212
.configure_mesh()
213-
.bold_line_style(&plotters::style::colors::BLUE.mix(0.1))
214-
.light_line_style(&plotters::style::colors::BLUE.mix(0.05))
215-
.axis_style(ShapeStyle::from(&plotters::style::colors::BLUE.mix(0.45)).stroke_width(1))
213+
.bold_line_style(plotters::style::colors::BLUE.mix(0.1))
214+
.light_line_style(plotters::style::colors::BLUE.mix(0.05))
215+
.axis_style(ShapeStyle::from(plotters::style::colors::BLUE.mix(0.45)).stroke_width(1))
216216
.y_labels(10)
217217
.y_label_style(
218218
("sans-serif", 15)
@@ -229,9 +229,9 @@ impl Chart<Message> for ExampleChart {
229229
AreaSeries::new(
230230
self.data_points.iter().cloned(),
231231
0_f32,
232-
&PLOT_LINE_COLOR.mix(0.175),
232+
PLOT_LINE_COLOR.mix(0.175),
233233
)
234-
.border_style(ShapeStyle::from(&PLOT_LINE_COLOR).stroke_width(2)),
234+
.border_style(ShapeStyle::from(PLOT_LINE_COLOR).stroke_width(2)),
235235
)
236236
.expect("failed to draw chart data");
237237
}

examples/mouse_events.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,11 @@ impl Application for State {
4747
Message::MouseEvent(event, point) => {
4848
self.chart.set_current_position(point);
4949
match event {
50-
iced::mouse::Event::ButtonPressed(button) => {
51-
if let iced::mouse::Button::Left = button {
52-
self.chart.set_down(true);
53-
}
50+
iced::mouse::Event::ButtonPressed(iced::mouse::Button::Left) => {
51+
self.chart.set_down(true);
5452
}
55-
iced::mouse::Event::ButtonReleased(button) => {
56-
if let iced::mouse::Button::Left = button {
57-
self.chart.set_down(false);
58-
}
53+
iced::mouse::Event::ButtonReleased(iced::mouse::Button::Left) => {
54+
self.chart.set_down(false);
5955
}
6056
_ => {
6157
// Do nothing
@@ -116,12 +112,12 @@ impl ArtChart {
116112

117113
fn nearby(p0: (f32, f32), p1: (f32, f32)) -> bool {
118114
let delta = (p1.0 - p0.0, p1.1 - p0.1);
119-
return (delta.0 * delta.0 + delta.1 * delta.1).sqrt() <= 1.0;
115+
(delta.0 * delta.0 + delta.1 * delta.1).sqrt() <= 1.0
120116
}
121117

122118
fn set_down(&mut self, new_is_down: bool) {
123119
if !self.is_down && new_is_down {
124-
self.initial_down_position = self.current_position.clone();
120+
self.initial_down_position = self.current_position;
125121
}
126122

127123
if self.is_down && !new_is_down {
@@ -163,9 +159,9 @@ impl Chart<Message> for ArtChart {
163159

164160
chart
165161
.configure_mesh()
166-
.bold_line_style(&colors::BLACK.mix(0.1))
167-
.light_line_style(&colors::BLACK.mix(0.05))
168-
.axis_style(ShapeStyle::from(&colors::BLACK.mix(0.45)).stroke_width(1))
162+
.bold_line_style(colors::BLACK.mix(0.1))
163+
.light_line_style(colors::BLACK.mix(0.05))
164+
.axis_style(ShapeStyle::from(colors::BLACK.mix(0.45)).stroke_width(1))
169165
.y_labels(10)
170166
.y_label_style(
171167
("sans-serif", 15)
@@ -181,7 +177,7 @@ impl Chart<Message> for ArtChart {
181177
.draw_series(
182178
self.points
183179
.iter()
184-
.map(|p| Circle::new(p.clone(), 5_i32, POINT_COLOR.filled())),
180+
.map(|p| Circle::new(*p, 5_i32, POINT_COLOR.filled())),
185181
)
186182
.expect("Failed to draw points");
187183

@@ -201,7 +197,7 @@ impl Chart<Message> for ArtChart {
201197
if Self::nearby(initial_p, current_p) {
202198
chart
203199
.draw_series(std::iter::once(Circle::new(
204-
current_p.clone(),
200+
current_p,
205201
5_i32,
206202
PREVIEW_COLOR.filled(),
207203
)))
@@ -215,16 +211,14 @@ impl Chart<Message> for ArtChart {
215211
.expect("Failed to draw preview line");
216212
}
217213
}
218-
} else {
219-
if let Some(current_p) = self.current_position {
220-
chart
221-
.draw_series(std::iter::once(Circle::new(
222-
current_p.clone(),
223-
5_i32,
224-
HOVER_COLOR.filled(),
225-
)))
226-
.expect("Failed to draw hover point");
227-
}
214+
} else if let Some(current_p) = self.current_position {
215+
chart
216+
.draw_series(std::iter::once(Circle::new(
217+
current_p,
218+
5_i32,
219+
HOVER_COLOR.filled(),
220+
)))
221+
.expect("Failed to draw hover point");
228222
}
229223

230224
*self.spec.borrow_mut() = Some(chart.as_coord_spec().clone());

0 commit comments

Comments
 (0)