Skip to content

Commit 2cf9bd1

Browse files
authored
Merge pull request #636 from plotters-rs/clippy
Apply most clippy lints
2 parents 99474cd + 6290f4c commit 2cf9bd1

File tree

25 files changed

+66
-93
lines changed

25 files changed

+66
-93
lines changed

plotters-backend/src/rasterizer/polygon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Edge {
4949

5050
impl PartialOrd for Edge {
5151
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
52-
self.get_slave_pos().partial_cmp(&other.get_slave_pos())
52+
Some(self.cmp(other))
5353
}
5454
}
5555

plotters-bitmap/src/bitmap_pixel/bgrx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl PixelFormat for BGRXPixel {
3636
a: f64,
3737
) {
3838
let (w, h) = target.get_size();
39-
let a = a.min(1.0).max(0.0);
39+
let a = a.clamp(0.0, 1.0);
4040
if a == 0.0 {
4141
return;
4242
}

plotters-bitmap/src/bitmap_pixel/rgb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl PixelFormat for RGBPixel {
4040
a: f64,
4141
) {
4242
let (w, h) = target.get_size();
43-
let a = a.min(1.0).max(0.0);
43+
let a = a.clamp(0.0, 1.0);
4444
if a == 0.0 {
4545
return;
4646
}

plotters-svg/src/svg.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,13 @@ fn make_svg_opacity(color: BackendColor) -> String {
2727
enum Target<'a> {
2828
File(String, &'a Path),
2929
Buffer(&'a mut String),
30-
// TODO: At this point we won't make the breaking change
31-
// so the u8 buffer is still supported. But in 0.3, we definitely
32-
// should get rid of this.
33-
#[cfg(feature = "deprecated_items")]
34-
U8Buffer(String, &'a mut Vec<u8>),
3530
}
3631

3732
impl Target<'_> {
3833
fn get_mut(&mut self) -> &mut String {
3934
match self {
4035
Target::File(ref mut buf, _) => buf,
4136
Target::Buffer(buf) => buf,
42-
#[cfg(feature = "deprecated_items")]
43-
Target::U8Buffer(ref mut buf, _) => buf,
4437
}
4538
}
4639
}
@@ -147,24 +140,6 @@ impl<'a> SVGBackend<'a> {
147140
ret
148141
}
149142

150-
/// Create a new SVG drawing backend and store the document into a u8 vector
151-
#[cfg(feature = "deprecated_items")]
152-
#[deprecated(
153-
note = "This will be replaced by `with_string`, consider use `with_string` to avoid breaking change in the future"
154-
)]
155-
pub fn with_buffer(buf: &'a mut Vec<u8>, size: (u32, u32)) -> Self {
156-
let mut ret = Self {
157-
target: Target::U8Buffer(String::default(), buf),
158-
size,
159-
tag_stack: vec![],
160-
saved: false,
161-
};
162-
163-
ret.init_svg_file(size);
164-
165-
ret
166-
}
167-
168143
/// Create a new SVG drawing backend and store the document into a String buffer
169144
pub fn with_string(buf: &'a mut String, size: (u32, u32)) -> Self {
170145
let mut ret = Self {
@@ -203,11 +178,6 @@ impl<'a> DrawingBackend for SVGBackend<'a> {
203178
.map_err(DrawingErrorKind::DrawingError)?;
204179
}
205180
Target::Buffer(_) => {}
206-
#[cfg(feature = "deprecated_items")]
207-
Target::U8Buffer(ref actual, ref mut target) => {
208-
target.clear();
209-
target.extend_from_slice(actual.as_bytes());
210-
}
211181
}
212182
self.saved = true;
213183
}
@@ -481,11 +451,11 @@ impl<'a> DrawingBackend for SVGBackend<'a> {
481451
}
482452

483453
#[cfg(all(not(target_arch = "wasm32"), feature = "image"))]
484-
fn blit_bitmap<'b>(
454+
fn blit_bitmap(
485455
&mut self,
486456
pos: BackendCoord,
487457
(w, h): (u32, u32),
488-
src: &'b [u8],
458+
src: &[u8],
489459
) -> Result<(), DrawingErrorKind<Self::ErrorType>> {
490460
use image::codecs::png::PngEncoder;
491461
use image::ImageEncoder;
@@ -508,9 +478,7 @@ impl<'a> DrawingBackend for SVGBackend<'a> {
508478
}
509479

510480
let padding = (3 - data.len() % 3) % 3;
511-
for _ in 0..padding {
512-
data.push(0);
513-
}
481+
data.resize(data.len() + padding, 0);
514482

515483
let mut rem_bits = 0;
516484
let mut rem_num = 0;

plotters/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.3.6"
44
authors = ["Hao Hou <haohou302@gmail.com>"]
55
edition = "2018"
66
license = "MIT"
7+
msrv = "1.56"
78
description = "A Rust drawing library focus on data plotting for both WASM and native applications"
89
repository = "https://github.com/plotters-rs/plotters"
910
homepage = "https://plotters-rs.github.io/"
@@ -12,6 +13,10 @@ categories = ["visualization", "wasm"]
1213
readme = "../README.md"
1314
exclude = ["doc-template", "plotters-doc-data"]
1415

16+
[lints.rust]
17+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] }
18+
deprecated = { level = "allow" }
19+
1520
[dependencies]
1621
num-traits = "0.2.14"
1722
chrono = { version = "0.4.32", optional = true }

plotters/clippy.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

plotters/examples/3d-plot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
99
let z_axis = (-3.0..3.0).step(0.1);
1010

1111
let mut chart = ChartBuilder::on(&area)
12-
.caption("3D Plot Test".to_string(), ("sans", 20))
12+
.caption("3D Plot Test", ("sans", 20))
1313
.build_cartesian_3d(x_axis.clone(), -3.0..3.0, z_axis.clone())?;
1414

1515
chart.with_projection(|mut pb| {

plotters/examples/matshow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1111
.margin(5)
1212
.top_x_label_area_size(40)
1313
.y_label_area_size(40)
14-
.build_cartesian_2d(0i32..15i32, 15i32..0i32)?;
14+
.build_cartesian_2d(0i32..15i32, 0i32..15i32)?;
1515

1616
chart
1717
.configure_mesh()

plotters/src/chart/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a, 'b, DB: DrawingBackend> ChartBuilder<'a, 'b, DB> {
194194
Sets the size of the X label area at the bottom of the chart.
195195
196196
- `size`: The desired size of the X label area in backend units (pixels).
197-
If set to 0, the X label area is removed.
197+
If set to 0, the X label area is removed.
198198
199199
See [`ChartBuilder::on()`] for more information and examples.
200200
*/
@@ -206,7 +206,7 @@ impl<'a, 'b, DB: DrawingBackend> ChartBuilder<'a, 'b, DB> {
206206
Sets the size of the Y label area to the left of the chart.
207207
208208
- `size`: The desired size of the Y label area in backend units (pixels).
209-
If set to 0, the Y label area is removed.
209+
If set to 0, the Y label area is removed.
210210
211211
See [`ChartBuilder::on()`] for more information and examples.
212212
*/
@@ -218,7 +218,7 @@ impl<'a, 'b, DB: DrawingBackend> ChartBuilder<'a, 'b, DB> {
218218
Sets the size of the X label area at the top of the chart.
219219
220220
- `size`: The desired size of the top X label area in backend units (pixels).
221-
If set to 0, the top X label area is removed.
221+
If set to 0, the top X label area is removed.
222222
223223
See [`ChartBuilder::on()`] for more information and examples.
224224
*/
@@ -230,7 +230,7 @@ impl<'a, 'b, DB: DrawingBackend> ChartBuilder<'a, 'b, DB> {
230230
Sets the size of the Y label area to the right of the chart.
231231
232232
- `size`: The desired size of the Y label area in backend units (pixels).
233-
If set to 0, the Y label area to the right is removed.
233+
If set to 0, the Y label area to the right is removed.
234234
235235
See [`ChartBuilder::on()`] for more information and examples.
236236
*/
@@ -243,7 +243,7 @@ impl<'a, 'b, DB: DrawingBackend> ChartBuilder<'a, 'b, DB> {
243243
244244
- `pos`: The position of the desired label area to adjust
245245
- `size`: The desired size of the label area in backend units (pixels).
246-
If set to 0, the label area is removed.
246+
If set to 0, the label area is removed.
247247
248248
See [`ChartBuilder::on()`] for more information and examples.
249249
*/

plotters/src/chart/context/cartesian3d/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ where
106106
/// Override the 3D projection matrix. This function allows to override the default projection
107107
/// matrix.
108108
/// - `pf`: A function that takes the default projection matrix configuration and returns the
109-
/// projection matrix. This function will allow you to adjust the pitch, yaw angle and the
110-
/// centeral point of the projection, etc. You can also build a projection matrix which is not
111-
/// relies on the default configuration as well.
109+
/// projection matrix. This function will allow you to adjust the pitch, yaw angle and the
110+
/// centeral point of the projection, etc. You can also build a projection matrix which is not
111+
/// relies on the default configuration as well.
112112
pub fn with_projection<P: FnOnce(ProjectionMatrixBuilder) -> ProjectionMatrix>(
113113
&mut self,
114114
pf: P,

0 commit comments

Comments
 (0)