From a8bc1555c2191a6f16d2f4e2a0de110e4069496a Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Sat, 19 Oct 2024 15:09:15 +0200 Subject: [PATCH 1/3] remove clippy pedantic --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dc9f457..6b03254 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -63,7 +63,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@clippy - - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic + - run: cargo clippy --tests -- -Dclippy::all # outdated: # name: Outdated From a27dcf013fb25a4f54abfaadcf977218982b1da2 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Sat, 19 Oct 2024 15:34:03 +0200 Subject: [PATCH 2/3] make clippy happy --- src/flutclient.rs | 2 +- src/main.rs | 13 +++---------- src/protocols.rs | 7 +++---- src/protocols/binary_protocol.rs | 22 ++++++++-------------- src/protocols/text_protocol.rs | 21 ++++++++++----------- src/utils.rs | 15 +++++---------- 6 files changed, 30 insertions(+), 50 deletions(-) diff --git a/src/flutclient.rs b/src/flutclient.rs index 95eab47..3e12e1e 100644 --- a/src/flutclient.rs +++ b/src/flutclient.rs @@ -107,7 +107,7 @@ where fn change_protocol(&mut self, protocol: &Protocol) { match protocol { Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::new(0)), - Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::new()), + Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::default()), } } diff --git a/src/main.rs b/src/main.rs index 518c88c..df07e74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,12 @@ use std::{ - collections::VecDeque, fs::{create_dir_all, File}, - io::{self, Error, ErrorKind}, + io::{self}, path::Path, - sync::{atomic::AtomicU64, Arc}, + sync::Arc, time::Duration, }; use chrono::Local; -use debug_print::{debug_eprintln, debug_println}; use flurry::{ config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL}, flutclient::FlutClient, @@ -16,11 +14,7 @@ use flurry::{ COUNTER, }; use image::{codecs::jpeg::JpegEncoder, GenericImageView, SubImage}; -use tokio::{ - io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}, - net::TcpListener, - time::{interval, sleep, timeout, Instant}, -}; +use tokio::{net::TcpListener, time::interval}; /// This function logs the current amount of changed pixels to stdout every second async fn pixel_change_stdout_log() -> io::Result<()> { @@ -46,7 +40,6 @@ async fn save_image_frames(grids: Arc<[grid::Flut]>, duration: Duration) -> timer.tick().await; for grid in grids.as_ref() { let p = base_dir.join(format!("{}", Local::now().format("%Y-%m-%d %H:%M:%S"))); - debug_println!("timer ticked, grid writing to {:?}", p); let mut file_writer = File::create(p)?; let encoder = JpegEncoder::new_with_quality(&mut file_writer, 50); diff --git a/src/protocols.rs b/src/protocols.rs index dabdb38..12aa1a6 100644 --- a/src/protocols.rs +++ b/src/protocols.rs @@ -9,21 +9,20 @@ use tokio::io::AsyncWriteExt; use crate::{Canvas, Command, Response}; -pub trait Parser +pub(crate) trait Parser where R: std::marker::Unpin + tokio::io::AsyncBufRead, { async fn parse(&self, reader: &mut R) -> io::Result; } -pub trait IOProtocol { +pub(crate) trait IOProtocol { fn change_canvas(&mut self, canvas: Canvas) -> io::Result<()>; } -pub trait Responder +pub(crate) trait Responder where W: AsyncWriteExt + std::marker::Unpin, { async fn unparse(&self, response: Response, writer: &mut W) -> io::Result<()>; } - diff --git a/src/protocols/binary_protocol.rs b/src/protocols/binary_protocol.rs index 2c7ea5c..d06711b 100644 --- a/src/protocols/binary_protocol.rs +++ b/src/protocols/binary_protocol.rs @@ -13,15 +13,9 @@ const SET_PX_RGB_BIN: u8 = 128; const SET_PX_RGBA_BIN: u8 = 129; const SET_PX_W_BIN: u8 = 130; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct BinaryParser {} -impl BinaryParser { - pub fn new() -> BinaryParser { - BinaryParser {} - } -} - impl Parser for BinaryParser { async fn parse(&self, reader: &mut R) -> io::Result { let fst = reader.read_u8().await; @@ -133,7 +127,7 @@ mod tests { #[tokio::test] async fn test_bin_help_parse() { - let parser = BinaryParser::new(); + let parser = BinaryParser::default(); let reader = tokio_test::io::Builder::new().read(&[HELP_BIN]).build(); let mut bufreader = BufReader::new(reader); let thingy = parser.parse(&mut bufreader).await; @@ -142,7 +136,7 @@ mod tests { #[tokio::test] async fn test_bin_size_parse() { - let parser = BinaryParser::new(); + let parser = BinaryParser::default(); let reader = tokio_test::io::Builder::new().read(&[SIZE_BIN, 3]).build(); let mut bufreader = BufReader::new(reader); let thingy = parser.parse(&mut bufreader).await; @@ -151,7 +145,7 @@ mod tests { #[tokio::test] async fn test_bin_px_set_w_parse() { - let parser = BinaryParser::new(); + let parser = BinaryParser::default(); let reader = tokio_test::io::Builder::new() .read(&[SET_PX_W_BIN, 0x01, 0x69, 0x42, 0x42, 0x69, 0x82]) .build(); @@ -165,7 +159,7 @@ mod tests { #[tokio::test] async fn test_bin_px_set_rgb_parse() { - let parser = BinaryParser::new(); + let parser = BinaryParser::default(); let reader = tokio_test::io::Builder::new() .read(&[ SET_PX_RGB_BIN, @@ -189,7 +183,7 @@ mod tests { #[tokio::test] async fn test_bin_px_set_rgba_parse() { - let parser = BinaryParser::new(); + let parser = BinaryParser::default(); let reader = tokio_test::io::Builder::new() .read(&[ SET_PX_RGBA_BIN, @@ -214,7 +208,7 @@ mod tests { #[tokio::test] async fn test_bin_px_get_parse() { - let parser = BinaryParser::new(); + let parser = BinaryParser::default(); let reader = tokio_test::io::Builder::new() .read(&[GET_PX_BIN, 0x03, 0x69, 0x42, 0x42, 0x69]) .build(); @@ -225,7 +219,7 @@ mod tests { #[tokio::test] async fn test_bin_parse_multiple() { - let parser = BinaryParser::new(); + let parser = BinaryParser::default(); let reader = tokio_test::io::Builder::new() .read(&[ SET_PX_RGB_BIN, diff --git a/src/protocols/text_protocol.rs b/src/protocols/text_protocol.rs index 6b8f0a1..1c711a2 100644 --- a/src/protocols/text_protocol.rs +++ b/src/protocols/text_protocol.rs @@ -1,6 +1,5 @@ -use std::io::{self, Error, ErrorKind}; - use atoi_radix10::parse_from_str; +use std::io::{self, Error, ErrorKind}; use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncWriteExt}; use crate::{ @@ -10,7 +9,7 @@ use crate::{ use super::{IOProtocol, Parser, Responder}; -#[derive(Clone)] +#[derive(Clone, Default)] pub struct TextParser { canvas: Canvas, } @@ -171,7 +170,7 @@ mod tests { #[tokio::test] async fn test_help_parse() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new().read(b"HELP\n").build(); let mut bufreader = BufReader::new(reader); let thingy = parser.parse(&mut bufreader).await; @@ -180,7 +179,7 @@ mod tests { #[tokio::test] async fn test_size_parse() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new().read(b"SIZE\n").build(); let mut bufreader = BufReader::new(reader); let thingy = parser.parse(&mut bufreader).await; @@ -189,7 +188,7 @@ mod tests { #[tokio::test] async fn test_canvas_parse() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new().read(b"CANVAS 12\n").build(); let mut bufreader = BufReader::new(reader); let thingy = parser.parse(&mut bufreader).await; @@ -198,7 +197,7 @@ mod tests { #[tokio::test] async fn test_px_set_w_parse() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new() .read(b"PX 28283 29991 81\n") .build(); @@ -212,7 +211,7 @@ mod tests { #[tokio::test] async fn test_px_set_rgb_parse() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new() .read(b"PX 28283 29991 8800ff\n") .build(); @@ -226,7 +225,7 @@ mod tests { #[tokio::test] async fn test_px_set_rgba_parse() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new() .read(b"PX 28283 29991 8800ff28\n") .build(); @@ -240,7 +239,7 @@ mod tests { #[tokio::test] async fn test_px_get_parse() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new() .read(b"PX 28283 29991\n") .build(); @@ -251,7 +250,7 @@ mod tests { #[tokio::test] async fn parse_multiple() { - let parser = TextParser::new(0); + let parser = TextParser::default(); let reader = tokio_test::io::Builder::new() .read(b"CANVAS 12\n") .read(b"SIZE\n") diff --git a/src/utils.rs b/src/utils.rs index d882b7f..da6d161 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,7 +19,7 @@ impl RepeatSome { impl AsyncRead for RepeatSome { fn poll_read( self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, + _cx: &mut std::task::Context<'_>, buf: &mut tokio::io::ReadBuf<'_>, ) -> std::task::Poll> { while buf.remaining() > self.len { @@ -29,18 +29,13 @@ impl AsyncRead for RepeatSome { } } +#[derive(Default)] pub struct Drain {} -impl Drain { - pub fn new() -> Self { - Drain {} - } -} - impl AsyncWrite for Drain { fn poll_write( self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, + _cx: &mut std::task::Context<'_>, buf: &[u8], ) -> Poll> { Poll::Ready(Ok(buf.len())) @@ -48,14 +43,14 @@ impl AsyncWrite for Drain { fn poll_flush( self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, + _cx: &mut std::task::Context<'_>, ) -> Poll> { Poll::Ready(Ok(())) } fn poll_shutdown( self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, + _cx: &mut std::task::Context<'_>, ) -> Poll> { Poll::Ready(Ok(())) } From 721e3fca34667e1e13f31859d6e1eefd3e7d4d2e Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Sat, 19 Oct 2024 15:38:51 +0200 Subject: [PATCH 3/3] use default for textprotocol --- src/flutclient.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/flutclient.rs b/src/flutclient.rs index 3e12e1e..c890b67 100644 --- a/src/flutclient.rs +++ b/src/flutclient.rs @@ -106,7 +106,7 @@ where fn change_protocol(&mut self, protocol: &Protocol) { match protocol { - Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::new(0)), + Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::default()), Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::default()), } } @@ -116,7 +116,7 @@ where reader: BufReader::new(reader), writer: BufWriter::new(writer), grids, - parser: ParserTypes::TextParser(TextParser::new(0)), + parser: ParserTypes::TextParser(TextParser::default()), counter: 0, } }