Skip to content

Commit 0dc4ae0

Browse files
authored
Merge pull request #82 from sorairolake/fix-clippy
chore: Apply clippy lints
2 parents bceee3e + c6cebef commit 0dc4ae0

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

src/canvas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ impl Canvas {
17961796
let dark_modules = self.modules.iter().filter(|m| m.is_dark()).count();
17971797
let total_modules = self.modules.len();
17981798
let ratio = dark_modules * 200 / total_modules;
1799-
if ratio >= 100 { ratio - 100 } else { 100 - ratio }.as_u16()
1799+
ratio.abs_diff(100).as_u16()
18001800
}
18011801

18021802
/// Compute the penalty score for having too many light modules on the sides.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl QrCode {
264264
///
265265
/// Note: the `image` crate itself also provides method to rotate the image,
266266
/// or overlay a logo on top of the QR code.
267-
pub fn render<P: Pixel>(&self) -> Renderer<P> {
267+
pub fn render<P: Pixel>(&self) -> Renderer<'_, P> {
268268
let quiet_zone = if self.version.is_micro() { 2 } else { 4 };
269269
Renderer::new(&self.content, self.width, quiet_zone)
270270
}

src/optimize.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct Parser<'a> {
8585
pending_single_byte: bool,
8686
}
8787

88-
impl<'a> Parser<'a> {
88+
impl Parser<'_> {
8989
/// Creates a new iterator which parse the data into segments that only
9090
/// contains their exclusive subsets. No optimization is done at this point.
9191
///
@@ -103,7 +103,7 @@ impl<'a> Parser<'a> {
103103
/// ]
104104
/// );
105105
/// ```
106-
pub fn new(data: &[u8]) -> Parser {
106+
pub fn new(data: &[u8]) -> Parser<'_> {
107107
Parser {
108108
ecs_iter: EcsIter { base: data.iter(), index: 0, ended: false },
109109
state: State::Init,
@@ -113,7 +113,7 @@ impl<'a> Parser<'a> {
113113
}
114114
}
115115

116-
impl<'a> Iterator for Parser<'a> {
116+
impl Iterator for Parser<'_> {
117117
type Item = Segment;
118118

119119
fn next(&mut self) -> Option<Segment> {
@@ -124,10 +124,7 @@ impl<'a> Iterator for Parser<'a> {
124124
}
125125

126126
loop {
127-
let (i, ecs) = match self.ecs_iter.next() {
128-
None => return None,
129-
Some(a) => a,
130-
};
127+
let (i, ecs) = self.ecs_iter.next()?;
131128
let (next_state, action) = STATE_TRANSITION[self.state as usize + ecs as usize];
132129
self.state = next_state;
133130

@@ -289,7 +286,7 @@ impl<I: Iterator<Item = Segment>> Optimizer<I> {
289286
}
290287
}
291288

292-
impl<'a> Parser<'a> {
289+
impl Parser<'_> {
293290
pub fn optimize(self, version: Version) -> Optimizer<Self> {
294291
Optimizer::new(self, version)
295292
}

src/render/eps.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Pixel for Color {
3030
type Image = String;
3131

3232
fn default_color(color: ModuleColor) -> Self {
33-
Color(color.select(Default::default(), [1.0; 3]))
33+
Self(color.select(Default::default(), [1.0; 3]))
3434
}
3535
}
3636

@@ -45,7 +45,7 @@ impl RenderCanvas for Canvas {
4545
type Image = String;
4646

4747
fn new(width: u32, height: u32, dark_pixel: Color, light_pixel: Color) -> Self {
48-
Canvas {
48+
Self {
4949
eps: format!(
5050
concat!(
5151
"%!PS-Adobe-3.0 EPSF-3.0\n",

src/render/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Element for char {
2828
}
2929
}
3030

31-
impl<'a> Element for &'a str {
31+
impl Element for &str {
3232
fn default_color(color: Color) -> Self {
3333
color.select("\u{2588}", " ")
3434
}

src/render/unicode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ impl RenderCanvas for Canvas1x2 {
6767
{
6868
// Then zipping those 2 lines together into a single 2-bit number list.
6969
if rows.len() == 2 {
70-
rows[0].iter().zip(rows[1]).map(|(top, bot)| (top * 2 + bot)).collect::<Vec<u8>>()
70+
rows[0].iter().zip(rows[1]).map(|(top, bot)| top * 2 + bot).collect::<Vec<u8>>()
7171
} else {
72-
rows[0].iter().map(|top| (top * 2)).collect::<Vec<u8>>()
72+
rows[0].iter().map(|top| top * 2).collect::<Vec<u8>>()
7373
}
7474
}
7575
.into_iter()

0 commit comments

Comments
 (0)