make clippy happy
This commit is contained in:
parent
a8bc1555c2
commit
a27dcf013f
6 changed files with 30 additions and 50 deletions
|
|
@ -107,7 +107,7 @@ where
|
||||||
fn change_protocol(&mut self, protocol: &Protocol) {
|
fn change_protocol(&mut self, protocol: &Protocol) {
|
||||||
match protocol {
|
match protocol {
|
||||||
Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::new(0)),
|
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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
13
src/main.rs
13
src/main.rs
|
|
@ -1,14 +1,12 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::VecDeque,
|
|
||||||
fs::{create_dir_all, File},
|
fs::{create_dir_all, File},
|
||||||
io::{self, Error, ErrorKind},
|
io::{self},
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{atomic::AtomicU64, Arc},
|
sync::Arc,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use debug_print::{debug_eprintln, debug_println};
|
|
||||||
use flurry::{
|
use flurry::{
|
||||||
config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL},
|
config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL},
|
||||||
flutclient::FlutClient,
|
flutclient::FlutClient,
|
||||||
|
|
@ -16,11 +14,7 @@ use flurry::{
|
||||||
COUNTER,
|
COUNTER,
|
||||||
};
|
};
|
||||||
use image::{codecs::jpeg::JpegEncoder, GenericImageView, SubImage};
|
use image::{codecs::jpeg::JpegEncoder, GenericImageView, SubImage};
|
||||||
use tokio::{
|
use tokio::{net::TcpListener, time::interval};
|
||||||
io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter},
|
|
||||||
net::TcpListener,
|
|
||||||
time::{interval, sleep, timeout, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// This function logs the current amount of changed pixels to stdout every second
|
/// This function logs the current amount of changed pixels to stdout every second
|
||||||
async fn pixel_change_stdout_log() -> io::Result<()> {
|
async fn pixel_change_stdout_log() -> io::Result<()> {
|
||||||
|
|
@ -46,7 +40,6 @@ async fn save_image_frames(grids: Arc<[grid::Flut<u32>]>, duration: Duration) ->
|
||||||
timer.tick().await;
|
timer.tick().await;
|
||||||
for grid in grids.as_ref() {
|
for grid in grids.as_ref() {
|
||||||
let p = base_dir.join(format!("{}", Local::now().format("%Y-%m-%d %H:%M:%S")));
|
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 mut file_writer = File::create(p)?;
|
||||||
|
|
||||||
let encoder = JpegEncoder::new_with_quality(&mut file_writer, 50);
|
let encoder = JpegEncoder::new_with_quality(&mut file_writer, 50);
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,20 @@ use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
use crate::{Canvas, Command, Response};
|
use crate::{Canvas, Command, Response};
|
||||||
|
|
||||||
pub trait Parser<R>
|
pub(crate) trait Parser<R>
|
||||||
where
|
where
|
||||||
R: std::marker::Unpin + tokio::io::AsyncBufRead,
|
R: std::marker::Unpin + tokio::io::AsyncBufRead,
|
||||||
{
|
{
|
||||||
async fn parse(&self, reader: &mut R) -> io::Result<Command>;
|
async fn parse(&self, reader: &mut R) -> io::Result<Command>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IOProtocol {
|
pub(crate) trait IOProtocol {
|
||||||
fn change_canvas(&mut self, canvas: Canvas) -> io::Result<()>;
|
fn change_canvas(&mut self, canvas: Canvas) -> io::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Responder<W>
|
pub(crate) trait Responder<W>
|
||||||
where
|
where
|
||||||
W: AsyncWriteExt + std::marker::Unpin,
|
W: AsyncWriteExt + std::marker::Unpin,
|
||||||
{
|
{
|
||||||
async fn unparse(&self, response: Response, writer: &mut W) -> io::Result<()>;
|
async fn unparse(&self, response: Response, writer: &mut W) -> io::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,9 @@ const SET_PX_RGB_BIN: u8 = 128;
|
||||||
const SET_PX_RGBA_BIN: u8 = 129;
|
const SET_PX_RGBA_BIN: u8 = 129;
|
||||||
const SET_PX_W_BIN: u8 = 130;
|
const SET_PX_W_BIN: u8 = 130;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct BinaryParser {}
|
pub struct BinaryParser {}
|
||||||
|
|
||||||
impl BinaryParser {
|
|
||||||
pub fn new() -> BinaryParser {
|
|
||||||
BinaryParser {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<R: AsyncBufRead + AsyncBufReadExt + std::marker::Unpin> Parser<R> for BinaryParser {
|
impl<R: AsyncBufRead + AsyncBufReadExt + std::marker::Unpin> Parser<R> for BinaryParser {
|
||||||
async fn parse(&self, reader: &mut R) -> io::Result<Command> {
|
async fn parse(&self, reader: &mut R) -> io::Result<Command> {
|
||||||
let fst = reader.read_u8().await;
|
let fst = reader.read_u8().await;
|
||||||
|
|
@ -133,7 +127,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bin_help_parse() {
|
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 reader = tokio_test::io::Builder::new().read(&[HELP_BIN]).build();
|
||||||
let mut bufreader = BufReader::new(reader);
|
let mut bufreader = BufReader::new(reader);
|
||||||
let thingy = parser.parse(&mut bufreader).await;
|
let thingy = parser.parse(&mut bufreader).await;
|
||||||
|
|
@ -142,7 +136,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bin_size_parse() {
|
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 reader = tokio_test::io::Builder::new().read(&[SIZE_BIN, 3]).build();
|
||||||
let mut bufreader = BufReader::new(reader);
|
let mut bufreader = BufReader::new(reader);
|
||||||
let thingy = parser.parse(&mut bufreader).await;
|
let thingy = parser.parse(&mut bufreader).await;
|
||||||
|
|
@ -151,7 +145,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bin_px_set_w_parse() {
|
async fn test_bin_px_set_w_parse() {
|
||||||
let parser = BinaryParser::new();
|
let parser = BinaryParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(&[SET_PX_W_BIN, 0x01, 0x69, 0x42, 0x42, 0x69, 0x82])
|
.read(&[SET_PX_W_BIN, 0x01, 0x69, 0x42, 0x42, 0x69, 0x82])
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -165,7 +159,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bin_px_set_rgb_parse() {
|
async fn test_bin_px_set_rgb_parse() {
|
||||||
let parser = BinaryParser::new();
|
let parser = BinaryParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(&[
|
.read(&[
|
||||||
SET_PX_RGB_BIN,
|
SET_PX_RGB_BIN,
|
||||||
|
|
@ -189,7 +183,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bin_px_set_rgba_parse() {
|
async fn test_bin_px_set_rgba_parse() {
|
||||||
let parser = BinaryParser::new();
|
let parser = BinaryParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(&[
|
.read(&[
|
||||||
SET_PX_RGBA_BIN,
|
SET_PX_RGBA_BIN,
|
||||||
|
|
@ -214,7 +208,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bin_px_get_parse() {
|
async fn test_bin_px_get_parse() {
|
||||||
let parser = BinaryParser::new();
|
let parser = BinaryParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(&[GET_PX_BIN, 0x03, 0x69, 0x42, 0x42, 0x69])
|
.read(&[GET_PX_BIN, 0x03, 0x69, 0x42, 0x42, 0x69])
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -225,7 +219,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bin_parse_multiple() {
|
async fn test_bin_parse_multiple() {
|
||||||
let parser = BinaryParser::new();
|
let parser = BinaryParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(&[
|
.read(&[
|
||||||
SET_PX_RGB_BIN,
|
SET_PX_RGB_BIN,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use std::io::{self, Error, ErrorKind};
|
|
||||||
|
|
||||||
use atoi_radix10::parse_from_str;
|
use atoi_radix10::parse_from_str;
|
||||||
|
use std::io::{self, Error, ErrorKind};
|
||||||
use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -10,7 +9,7 @@ use crate::{
|
||||||
|
|
||||||
use super::{IOProtocol, Parser, Responder};
|
use super::{IOProtocol, Parser, Responder};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct TextParser {
|
pub struct TextParser {
|
||||||
canvas: Canvas,
|
canvas: Canvas,
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +170,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_help_parse() {
|
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 reader = tokio_test::io::Builder::new().read(b"HELP\n").build();
|
||||||
let mut bufreader = BufReader::new(reader);
|
let mut bufreader = BufReader::new(reader);
|
||||||
let thingy = parser.parse(&mut bufreader).await;
|
let thingy = parser.parse(&mut bufreader).await;
|
||||||
|
|
@ -180,7 +179,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_size_parse() {
|
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 reader = tokio_test::io::Builder::new().read(b"SIZE\n").build();
|
||||||
let mut bufreader = BufReader::new(reader);
|
let mut bufreader = BufReader::new(reader);
|
||||||
let thingy = parser.parse(&mut bufreader).await;
|
let thingy = parser.parse(&mut bufreader).await;
|
||||||
|
|
@ -189,7 +188,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_canvas_parse() {
|
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 reader = tokio_test::io::Builder::new().read(b"CANVAS 12\n").build();
|
||||||
let mut bufreader = BufReader::new(reader);
|
let mut bufreader = BufReader::new(reader);
|
||||||
let thingy = parser.parse(&mut bufreader).await;
|
let thingy = parser.parse(&mut bufreader).await;
|
||||||
|
|
@ -198,7 +197,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_px_set_w_parse() {
|
async fn test_px_set_w_parse() {
|
||||||
let parser = TextParser::new(0);
|
let parser = TextParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(b"PX 28283 29991 81\n")
|
.read(b"PX 28283 29991 81\n")
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -212,7 +211,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_px_set_rgb_parse() {
|
async fn test_px_set_rgb_parse() {
|
||||||
let parser = TextParser::new(0);
|
let parser = TextParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(b"PX 28283 29991 8800ff\n")
|
.read(b"PX 28283 29991 8800ff\n")
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -226,7 +225,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_px_set_rgba_parse() {
|
async fn test_px_set_rgba_parse() {
|
||||||
let parser = TextParser::new(0);
|
let parser = TextParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(b"PX 28283 29991 8800ff28\n")
|
.read(b"PX 28283 29991 8800ff28\n")
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -240,7 +239,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_px_get_parse() {
|
async fn test_px_get_parse() {
|
||||||
let parser = TextParser::new(0);
|
let parser = TextParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(b"PX 28283 29991\n")
|
.read(b"PX 28283 29991\n")
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -251,7 +250,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn parse_multiple() {
|
async fn parse_multiple() {
|
||||||
let parser = TextParser::new(0);
|
let parser = TextParser::default();
|
||||||
let reader = tokio_test::io::Builder::new()
|
let reader = tokio_test::io::Builder::new()
|
||||||
.read(b"CANVAS 12\n")
|
.read(b"CANVAS 12\n")
|
||||||
.read(b"SIZE\n")
|
.read(b"SIZE\n")
|
||||||
|
|
|
||||||
15
src/utils.rs
15
src/utils.rs
|
|
@ -19,7 +19,7 @@ impl RepeatSome {
|
||||||
impl AsyncRead for RepeatSome {
|
impl AsyncRead for RepeatSome {
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: std::pin::Pin<&mut Self>,
|
self: std::pin::Pin<&mut Self>,
|
||||||
cx: &mut std::task::Context<'_>,
|
_cx: &mut std::task::Context<'_>,
|
||||||
buf: &mut tokio::io::ReadBuf<'_>,
|
buf: &mut tokio::io::ReadBuf<'_>,
|
||||||
) -> std::task::Poll<std::io::Result<()>> {
|
) -> std::task::Poll<std::io::Result<()>> {
|
||||||
while buf.remaining() > self.len {
|
while buf.remaining() > self.len {
|
||||||
|
|
@ -29,18 +29,13 @@ impl AsyncRead for RepeatSome {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Drain {}
|
pub struct Drain {}
|
||||||
|
|
||||||
impl Drain {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Drain {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsyncWrite for Drain {
|
impl AsyncWrite for Drain {
|
||||||
fn poll_write(
|
fn poll_write(
|
||||||
self: std::pin::Pin<&mut Self>,
|
self: std::pin::Pin<&mut Self>,
|
||||||
cx: &mut std::task::Context<'_>,
|
_cx: &mut std::task::Context<'_>,
|
||||||
buf: &[u8],
|
buf: &[u8],
|
||||||
) -> Poll<Result<usize, std::io::Error>> {
|
) -> Poll<Result<usize, std::io::Error>> {
|
||||||
Poll::Ready(Ok(buf.len()))
|
Poll::Ready(Ok(buf.len()))
|
||||||
|
|
@ -48,14 +43,14 @@ impl AsyncWrite for Drain {
|
||||||
|
|
||||||
fn poll_flush(
|
fn poll_flush(
|
||||||
self: std::pin::Pin<&mut Self>,
|
self: std::pin::Pin<&mut Self>,
|
||||||
cx: &mut std::task::Context<'_>,
|
_cx: &mut std::task::Context<'_>,
|
||||||
) -> Poll<Result<(), std::io::Error>> {
|
) -> Poll<Result<(), std::io::Error>> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_shutdown(
|
fn poll_shutdown(
|
||||||
self: std::pin::Pin<&mut Self>,
|
self: std::pin::Pin<&mut Self>,
|
||||||
cx: &mut std::task::Context<'_>,
|
_cx: &mut std::task::Context<'_>,
|
||||||
) -> Poll<Result<(), std::io::Error>> {
|
) -> Poll<Result<(), std::io::Error>> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue