Skip to content

Commit afb89f2

Browse files
authored
Merge [#53]: Enforce Clippy's Will 📎
Merge pull request #53 from Shresht7:clippy
2 parents 04003a5 + 4985368 commit afb89f2

9 files changed

Lines changed: 43 additions & 44 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: cargo fmt --check
2121

2222
- name: Lint
23-
run: cargo clippy
23+
run: cargo clippy --all-targets -- -D warnings
2424

2525
- name: Check
2626
run: cargo check

src/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub enum Action {
1212
pub fn handle_events() -> std::io::Result<Action> {
1313
match crossterm::event::read()? {
1414
crossterm::event::Event::Key(event) if event.kind == KeyEventKind::Press => {
15-
return Ok(handle_key_event(event))
15+
return Ok(handle_key_event(event));
1616
}
1717
_ => (),
1818
}

src/helpers/colors.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ impl FromStr for RGBColor {
3636

3737
fn from_str(s: &str) -> Result<Self, Self::Err> {
3838
if s.starts_with('#') {
39-
return RGBColor::from_hex_str(s);
39+
RGBColor::from_hex_str(s)
4040
} else if s.contains(',') {
41-
return RGBColor::from_rgb_str(s);
41+
RGBColor::from_rgb_str(s)
4242
} else {
43-
return RGBColor::from_named_color(s);
43+
RGBColor::from_named_color(s)
4444
}
4545
}
4646
}
@@ -60,9 +60,9 @@ impl RGBColor {
6060
let parts: Vec<&str> = s.split(',').map(|part| part.trim()).collect();
6161
if parts.len() == 3 {
6262
if let (Ok(r), Ok(g), Ok(b)) = (parts[0].parse(), parts[1].parse(), parts[2].parse()) {
63-
return Ok(Self(r, g, b));
63+
Ok(Self(r, g, b))
6464
} else {
65-
return Err(ParseErrorKind::InvalidFormat(s.to_string()));
65+
Err(ParseErrorKind::InvalidFormat(s.to_string()))
6666
}
6767
} else {
6868
Err(ParseErrorKind::InvalidFormat(s.to_string()))
@@ -90,9 +90,9 @@ impl std::ops::Mul<f32> for RGBColor {
9090

9191
fn mul(self, rhs: f32) -> Self::Output {
9292
RGBColor(
93-
(self.r() as f32 * rhs).min(255.0).max(0.0) as u8,
94-
(self.g() as f32 * rhs).min(255.0).max(0.0) as u8,
95-
(self.b() as f32 * rhs).min(255.0).max(0.0) as u8,
93+
(self.r() as f32 * rhs).clamp(0.0, 255.0) as u8,
94+
(self.g() as f32 * rhs).clamp(0.0, 255.0) as u8,
95+
(self.b() as f32 * rhs).clamp(0.0, 255.0) as u8,
9696
)
9797
}
9898
}
@@ -106,6 +106,7 @@ pub struct LinearGradient {
106106
end: RGBColor,
107107
}
108108

109+
#[allow(dead_code)]
109110
pub struct LinearGradientSteps<'a> {
110111
gradient: &'a LinearGradient,
111112
current: usize,
@@ -143,7 +144,7 @@ impl LinearGradient {
143144
/// Interpolate between two colors. The factor has to be between 0 and 1
144145
pub fn interpolate(&self, factor: f32) -> RGBColor {
145146
assert!(
146-
factor >= 0.0 && factor <= 1.0,
147+
(0.0..=1.0).contains(&factor),
147148
"The factor value must be between 0 and 1"
148149
);
149150
let delta = self.delta();
@@ -225,10 +226,8 @@ mod tests {
225226
assert_eq!(RGBColor::from_hex_str("#00FF00"), Ok(RGBColor(0, 255, 0)));
226227
assert_eq!(RGBColor::from_hex_str("#0000FF"), Ok(RGBColor(0, 0, 255)));
227228
assert!(
228-
RGBColor::from_hex_str("#GGGGGG").is_err_and(|x| match x {
229-
ParseErrorKind::InvalidHexValue(_) => true,
230-
_ => false,
231-
}),
229+
RGBColor::from_hex_str("#GGGGGG")
230+
.is_err_and(|x| { matches!(x, ParseErrorKind::InvalidHexValue(_)) }),
232231
"Invalid Hex Format"
233232
)
234233
}

src/helpers/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn ansi_rgb(s: &char, color: colors::RGBColor) -> String {
1313
color.r(),
1414
color.g(),
1515
color.b(),
16-
s.to_string()
16+
s
1717
)
1818
}
1919

src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::io::Write;
22

33
use clap::Parser;
44
use crossterm::{
5-
cursor,
6-
style::{style, Stylize},
7-
terminal, QueueableCommand,
5+
QueueableCommand, cursor,
6+
style::{Stylize, style},
7+
terminal,
88
};
99

1010
mod config;
@@ -40,7 +40,7 @@ fn run(config: &config::Config) -> std::io::Result<()> {
4040
let (columns, rows) = terminal::size()?;
4141

4242
// Instantiate the matrix streams
43-
let mut matrix = matrix::Matrix::new(rows, columns, &config);
43+
let mut matrix = matrix::Matrix::new(rows, columns, config);
4444

4545
// Setup the terminal before running the application
4646
setup(&mut stdout)?;
@@ -51,13 +51,13 @@ fn run(config: &config::Config) -> std::io::Result<()> {
5151
// Render the Matrix-Rain on screen
5252
loop {
5353
// Render each stream
54-
matrix.render(&config, &mut stdout)?;
54+
matrix.render(config, &mut stdout)?;
5555

5656
// Handle events
57-
if crossterm::event::poll(std::time::Duration::from_millis(1000 / config.fps as u64))? {
58-
if let events::Action::Exit = events::handle_events()? {
59-
break;
60-
}
57+
if crossterm::event::poll(std::time::Duration::from_millis(1000 / config.fps as u64))?
58+
&& let events::Action::Exit = events::handle_events()?
59+
{
60+
break;
6161
}
6262
}
6363

src/matrix/entity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crossterm::QueueableCommand;
12
use crossterm::cursor;
23
use crossterm::style::Print;
3-
use crossterm::QueueableCommand;
44

55
use crate::config;
66
use crate::helpers::{colors, utils};
@@ -84,7 +84,7 @@ impl Entity {
8484
/// If the `frame_count` has exceeded `switch_interval` switch the [Entity] symbol to
8585
/// another one from the character set.
8686
fn switch_symbol(&mut self) {
87-
if self.frame_count % self.switch_interval == 0 {
87+
if self.frame_count.is_multiple_of(self.switch_interval) {
8888
self.set_symbol();
8989
}
9090
self.frame_count += 1;

src/matrix/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ mod entity;
1010
mod stream;
1111

1212
use crossterm::{
13+
QueueableCommand,
1314
cursor::{self, MoveToNextLine},
1415
style::Print,
15-
QueueableCommand,
1616
};
1717
use stream::Stream;
1818

@@ -106,7 +106,7 @@ impl Matrix {
106106
}
107107

108108
// Return the instance
109-
return ret;
109+
ret
110110
}
111111

112112
/// The setup function is called once before the draw loop starts

src/matrix/stream.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crossterm::QueueableCommand;
12
use crossterm::cursor;
23
use crossterm::style::Print;
3-
use crossterm::QueueableCommand;
44

55
use crate::config;
66
use crate::helpers::{colors, direction::Direction, utils};
@@ -39,7 +39,7 @@ impl Stream {
3939
count: 10,
4040
};
4141
stream.generate_entities(config);
42-
return stream;
42+
stream
4343
}
4444

4545
/// Generate the entities that constitute the stream
@@ -77,8 +77,8 @@ impl Stream {
7777

7878
// Create the color gradient for the stream
7979
let gradient = colors::LinearGradient::new(
80-
colors::RGBColor::from(config.stream_color),
81-
colors::RGBColor::from(config.stream_color) * config.stream_color_gradient_factor, // Overloaded Operator for Scalar Multiplication
80+
config.stream_color,
81+
config.stream_color * config.stream_color_gradient_factor, // Overloaded Operator for Scalar Multiplication
8282
);
8383

8484
// Create the following entities

src/symbols.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub enum Symbols {
1616
/// Decimal Numbers: From 0 to 9
1717
Decimal,
1818
/// ASCII Symbols: Printable characters from 33 to 126 (0x21 to 0x7E). (from '!' to '~', including A-Z, a-z, 0-9 etc.)
19-
ASCII,
19+
Ascii,
2020
/// Mathematical Symbols: Various mathematical characters like: ∐, ∑, ≠, →
2121
Math,
2222
/// Braille Symbols: Unicode range from 0x2840 to 0x2840 + 63 (64 Braille patterns) (e.g ⠇, ⠾, ⣿)
@@ -36,7 +36,7 @@ impl FromStr for Symbols {
3636
"binary" | "bin" => Ok(Self::Binary),
3737
"decimal" | "numbers" | "digits" => Ok(Self::Decimal),
3838
"maths" | "math" | "mathematics" => Ok(Self::Math),
39-
"ascii" | "text" | "english" => Ok(Self::ASCII),
39+
"ascii" | "text" | "english" => Ok(Self::Ascii),
4040
"braille" | "dots" => Ok(Self::Braille),
4141
"emoji" | "cursed" => Ok(Self::Cursed),
4242
x => Ok(Self::Custom(x.to_string())),
@@ -58,22 +58,22 @@ impl Symbols {
5858
match self {
5959
Self::Original => {
6060
let r = utils::random_between(0x30a0, 0x30a0 + 96) as u32;
61-
return std::char::from_u32(r).unwrap_or('0');
61+
std::char::from_u32(r).unwrap_or('0')
6262
}
6363

6464
Self::Binary => {
6565
let r = utils::random_between(0, 2);
66-
return if r == 0 { '0' } else { '1' };
66+
if r == 0 { '0' } else { '1' }
6767
}
6868

6969
Self::Decimal => {
7070
let r = utils::random_between(0, 10);
71-
return std::char::from_digit(r, 10).unwrap_or('0');
71+
std::char::from_digit(r, 10).unwrap_or('0')
7272
}
7373

74-
Self::ASCII => {
74+
Self::Ascii => {
7575
let r = utils::random_between(33, 127) as u32;
76-
return std::char::from_u32(r).unwrap_or('0');
76+
std::char::from_u32(r).unwrap_or('0')
7777
}
7878

7979
Self::Math => {
@@ -85,22 +85,22 @@ impl Symbols {
8585
2 => utils::random_between(0x2190, 0x21FF) as u32, // Arrows
8686
_ => utils::random_between(0x27C0, 0x27EF) as u32, // Miscellaneous Mathematical Symbols
8787
};
88-
return std::char::from_u32(r).unwrap_or('0');
88+
std::char::from_u32(r).unwrap_or('0')
8989
}
9090

9191
Self::Braille => {
9292
let r = utils::random_between(0x2840, 0x2840 + 63) as u32;
93-
return std::char::from_u32(r).unwrap_or('0');
93+
std::char::from_u32(r).unwrap_or('0')
9494
}
9595

9696
Self::Cursed => {
9797
let r = utils::random_between(0x1f300, 0x1f3f0) as u32;
98-
return std::char::from_u32(r).unwrap_or('0');
98+
std::char::from_u32(r).unwrap_or('0')
9999
}
100100

101101
Self::Custom(s) => {
102102
let r = utils::random_between(0, s.len());
103-
return s.chars().nth(r).unwrap_or('0');
103+
s.chars().nth(r).unwrap_or('0')
104104
}
105105
}
106106
}

0 commit comments

Comments
 (0)