From ed9e9022e1e85fddb710112976f034e391d85adf Mon Sep 17 00:00:00 2001 From: Shresht Srivastav <59516096+Shresht7@users.noreply.github.com> Date: Tue, 7 Jul 2026 22:28:52 +0530 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=93=8E`cargo=20clippy=20--fix`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/colors.rs | 12 ++++++------ src/helpers/utils.rs | 2 +- src/main.rs | 18 +++++++++--------- src/matrix/entity.rs | 4 ++-- src/matrix/mod.rs | 4 ++-- src/matrix/stream.rs | 8 ++++---- src/symbols.rs | 16 ++++++++-------- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/helpers/colors.rs b/src/helpers/colors.rs index 83b8926..d14ecb2 100644 --- a/src/helpers/colors.rs +++ b/src/helpers/colors.rs @@ -36,11 +36,11 @@ impl FromStr for RGBColor { fn from_str(s: &str) -> Result { if s.starts_with('#') { - return RGBColor::from_hex_str(s); + RGBColor::from_hex_str(s) } else if s.contains(',') { - return RGBColor::from_rgb_str(s); + RGBColor::from_rgb_str(s) } else { - return RGBColor::from_named_color(s); + RGBColor::from_named_color(s) } } } @@ -60,9 +60,9 @@ impl RGBColor { let parts: Vec<&str> = s.split(',').map(|part| part.trim()).collect(); if parts.len() == 3 { if let (Ok(r), Ok(g), Ok(b)) = (parts[0].parse(), parts[1].parse(), parts[2].parse()) { - return Ok(Self(r, g, b)); + Ok(Self(r, g, b)) } else { - return Err(ParseErrorKind::InvalidFormat(s.to_string())); + Err(ParseErrorKind::InvalidFormat(s.to_string())) } } else { Err(ParseErrorKind::InvalidFormat(s.to_string())) @@ -143,7 +143,7 @@ impl LinearGradient { /// Interpolate between two colors. The factor has to be between 0 and 1 pub fn interpolate(&self, factor: f32) -> RGBColor { assert!( - factor >= 0.0 && factor <= 1.0, + (0.0..=1.0).contains(&factor), "The factor value must be between 0 and 1" ); let delta = self.delta(); diff --git a/src/helpers/utils.rs b/src/helpers/utils.rs index be5b5f6..2c9a5ac 100644 --- a/src/helpers/utils.rs +++ b/src/helpers/utils.rs @@ -13,7 +13,7 @@ pub fn ansi_rgb(s: &char, color: colors::RGBColor) -> String { color.r(), color.g(), color.b(), - s.to_string() + s ) } diff --git a/src/main.rs b/src/main.rs index 7eae3dd..33381b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,9 @@ use std::io::Write; use clap::Parser; use crossterm::{ - cursor, - style::{style, Stylize}, - terminal, QueueableCommand, + QueueableCommand, cursor, + style::{Stylize, style}, + terminal, }; mod config; @@ -40,7 +40,7 @@ fn run(config: &config::Config) -> std::io::Result<()> { let (columns, rows) = terminal::size()?; // Instantiate the matrix streams - let mut matrix = matrix::Matrix::new(rows, columns, &config); + let mut matrix = matrix::Matrix::new(rows, columns, config); // Setup the terminal before running the application setup(&mut stdout)?; @@ -51,13 +51,13 @@ fn run(config: &config::Config) -> std::io::Result<()> { // Render the Matrix-Rain on screen loop { // Render each stream - matrix.render(&config, &mut stdout)?; + matrix.render(config, &mut stdout)?; // Handle events - if crossterm::event::poll(std::time::Duration::from_millis(1000 / config.fps as u64))? { - if let events::Action::Exit = events::handle_events()? { - break; - } + if crossterm::event::poll(std::time::Duration::from_millis(1000 / config.fps as u64))? + && let events::Action::Exit = events::handle_events()? + { + break; } } diff --git a/src/matrix/entity.rs b/src/matrix/entity.rs index 0c95700..d551ee6 100644 --- a/src/matrix/entity.rs +++ b/src/matrix/entity.rs @@ -1,6 +1,6 @@ +use crossterm::QueueableCommand; use crossterm::cursor; use crossterm::style::Print; -use crossterm::QueueableCommand; use crate::config; use crate::helpers::{colors, utils}; @@ -84,7 +84,7 @@ impl Entity { /// If the `frame_count` has exceeded `switch_interval` switch the [Entity] symbol to /// another one from the character set. fn switch_symbol(&mut self) { - if self.frame_count % self.switch_interval == 0 { + if self.frame_count.is_multiple_of(self.switch_interval) { self.set_symbol(); } self.frame_count += 1; diff --git a/src/matrix/mod.rs b/src/matrix/mod.rs index 4a4e838..de8b880 100644 --- a/src/matrix/mod.rs +++ b/src/matrix/mod.rs @@ -10,9 +10,9 @@ mod entity; mod stream; use crossterm::{ + QueueableCommand, cursor::{self, MoveToNextLine}, style::Print, - QueueableCommand, }; use stream::Stream; @@ -106,7 +106,7 @@ impl Matrix { } // Return the instance - return ret; + ret } /// The setup function is called once before the draw loop starts diff --git a/src/matrix/stream.rs b/src/matrix/stream.rs index 7dadd50..8ff3b76 100644 --- a/src/matrix/stream.rs +++ b/src/matrix/stream.rs @@ -1,6 +1,6 @@ +use crossterm::QueueableCommand; use crossterm::cursor; use crossterm::style::Print; -use crossterm::QueueableCommand; use crate::config; use crate::helpers::{colors, direction::Direction, utils}; @@ -39,7 +39,7 @@ impl Stream { count: 10, }; stream.generate_entities(config); - return stream; + stream } /// Generate the entities that constitute the stream @@ -77,8 +77,8 @@ impl Stream { // Create the color gradient for the stream let gradient = colors::LinearGradient::new( - colors::RGBColor::from(config.stream_color), - colors::RGBColor::from(config.stream_color) * config.stream_color_gradient_factor, // Overloaded Operator for Scalar Multiplication + config.stream_color, + config.stream_color * config.stream_color_gradient_factor, // Overloaded Operator for Scalar Multiplication ); // Create the following entities diff --git a/src/symbols.rs b/src/symbols.rs index 50432fd..3a362f9 100644 --- a/src/symbols.rs +++ b/src/symbols.rs @@ -58,22 +58,22 @@ impl Symbols { match self { Self::Original => { let r = utils::random_between(0x30a0, 0x30a0 + 96) as u32; - return std::char::from_u32(r).unwrap_or('0'); + std::char::from_u32(r).unwrap_or('0') } Self::Binary => { let r = utils::random_between(0, 2); - return if r == 0 { '0' } else { '1' }; + if r == 0 { '0' } else { '1' } } Self::Decimal => { let r = utils::random_between(0, 10); - return std::char::from_digit(r, 10).unwrap_or('0'); + std::char::from_digit(r, 10).unwrap_or('0') } Self::ASCII => { let r = utils::random_between(33, 127) as u32; - return std::char::from_u32(r).unwrap_or('0'); + std::char::from_u32(r).unwrap_or('0') } Self::Math => { @@ -85,22 +85,22 @@ impl Symbols { 2 => utils::random_between(0x2190, 0x21FF) as u32, // Arrows _ => utils::random_between(0x27C0, 0x27EF) as u32, // Miscellaneous Mathematical Symbols }; - return std::char::from_u32(r).unwrap_or('0'); + std::char::from_u32(r).unwrap_or('0') } Self::Braille => { let r = utils::random_between(0x2840, 0x2840 + 63) as u32; - return std::char::from_u32(r).unwrap_or('0'); + std::char::from_u32(r).unwrap_or('0') } Self::Cursed => { let r = utils::random_between(0x1f300, 0x1f3f0) as u32; - return std::char::from_u32(r).unwrap_or('0'); + std::char::from_u32(r).unwrap_or('0') } Self::Custom(s) => { let r = utils::random_between(0, s.len()); - return s.chars().nth(r).unwrap_or('0'); + s.chars().nth(r).unwrap_or('0') } } } From 4d763764a9c491981137def33cec50de9cf189dc Mon Sep 17 00:00:00 2001 From: Shresht Srivastav <59516096+Shresht7@users.noreply.github.com> Date: Tue, 7 Jul 2026 22:30:26 +0530 Subject: [PATCH 2/5] Refactor RGBColor multiplication to use clamp for value limits and correct ASCII enum casing --- src/helpers/colors.rs | 6 +++--- src/symbols.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/helpers/colors.rs b/src/helpers/colors.rs index d14ecb2..17a57c7 100644 --- a/src/helpers/colors.rs +++ b/src/helpers/colors.rs @@ -90,9 +90,9 @@ impl std::ops::Mul for RGBColor { fn mul(self, rhs: f32) -> Self::Output { RGBColor( - (self.r() as f32 * rhs).min(255.0).max(0.0) as u8, - (self.g() as f32 * rhs).min(255.0).max(0.0) as u8, - (self.b() as f32 * rhs).min(255.0).max(0.0) as u8, + (self.r() as f32 * rhs).clamp(0.0, 255.0) as u8, + (self.g() as f32 * rhs).clamp(0.0, 255.0) as u8, + (self.b() as f32 * rhs).clamp(0.0, 255.0) as u8, ) } } diff --git a/src/symbols.rs b/src/symbols.rs index 3a362f9..bb6901a 100644 --- a/src/symbols.rs +++ b/src/symbols.rs @@ -16,7 +16,7 @@ pub enum Symbols { /// Decimal Numbers: From 0 to 9 Decimal, /// ASCII Symbols: Printable characters from 33 to 126 (0x21 to 0x7E). (from '!' to '~', including A-Z, a-z, 0-9 etc.) - ASCII, + Ascii, /// Mathematical Symbols: Various mathematical characters like: ∐, ∑, ≠, → Math, /// Braille Symbols: Unicode range from 0x2840 to 0x2840 + 63 (64 Braille patterns) (e.g ⠇, ⠾, ⣿) @@ -36,7 +36,7 @@ impl FromStr for Symbols { "binary" | "bin" => Ok(Self::Binary), "decimal" | "numbers" | "digits" => Ok(Self::Decimal), "maths" | "math" | "mathematics" => Ok(Self::Math), - "ascii" | "text" | "english" => Ok(Self::ASCII), + "ascii" | "text" | "english" => Ok(Self::Ascii), "braille" | "dots" => Ok(Self::Braille), "emoji" | "cursed" => Ok(Self::Cursed), x => Ok(Self::Custom(x.to_string())), @@ -71,7 +71,7 @@ impl Symbols { std::char::from_digit(r, 10).unwrap_or('0') } - Self::ASCII => { + Self::Ascii => { let r = utils::random_between(33, 127) as u32; std::char::from_u32(r).unwrap_or('0') } From 3b0ed6c26caa7ad5c2a763890a8e5f35a873520e Mon Sep 17 00:00:00 2001 From: Shresht Srivastav <59516096+Shresht7@users.noreply.github.com> Date: Tue, 7 Jul 2026 22:35:48 +0530 Subject: [PATCH 3/5] Add dead code allowance for `LinearGradientSteps` for now --- src/helpers/colors.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/helpers/colors.rs b/src/helpers/colors.rs index 17a57c7..3c1817a 100644 --- a/src/helpers/colors.rs +++ b/src/helpers/colors.rs @@ -106,6 +106,7 @@ pub struct LinearGradient { end: RGBColor, } +#[allow(dead_code)] pub struct LinearGradientSteps<'a> { gradient: &'a LinearGradient, current: usize, @@ -225,10 +226,8 @@ mod tests { assert_eq!(RGBColor::from_hex_str("#00FF00"), Ok(RGBColor(0, 255, 0))); assert_eq!(RGBColor::from_hex_str("#0000FF"), Ok(RGBColor(0, 0, 255))); assert!( - RGBColor::from_hex_str("#GGGGGG").is_err_and(|x| match x { - ParseErrorKind::InvalidHexValue(_) => true, - _ => false, - }), + RGBColor::from_hex_str("#GGGGGG") + .is_err_and(|x| { matches!(x, ParseErrorKind::InvalidHexValue(_)) }), "Invalid Hex Format" ) } From e804b3b704d393a4d27cdf1c62649a841d979535 Mon Sep 17 00:00:00 2001 From: Shresht Srivastav <59516096+Shresht7@users.noreply.github.com> Date: Tue, 7 Jul 2026 22:35:55 +0530 Subject: [PATCH 4/5] Enhance CI linting step to include all targets and treat warnings as errors --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bcb643..857f1c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: run: cargo fmt --check - name: Lint - run: cargo clippy + run: cargo clippy --all-targets -- -D warnings - name: Check run: cargo check From 498536877cdda733c64ed9737fe33473a4d5832d Mon Sep 17 00:00:00 2001 From: Shresht Srivastav <59516096+Shresht7@users.noreply.github.com> Date: Tue, 7 Jul 2026 22:39:38 +0530 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=92=84=20`cargo=20fmt`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events.rs b/src/events.rs index 88a3c61..e5a043e 100644 --- a/src/events.rs +++ b/src/events.rs @@ -12,7 +12,7 @@ pub enum Action { pub fn handle_events() -> std::io::Result { match crossterm::event::read()? { crossterm::event::Event::Key(event) if event.kind == KeyEventKind::Press => { - return Ok(handle_key_event(event)) + return Ok(handle_key_event(event)); } _ => (), }