From 496baabd1444c91f09c954af87bb40a8f3ac1a2e Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 16 Sep 2024 21:41:40 +0100 Subject: [PATCH] lint with clippy --- .devcontainer/setup.sh | 1 + .../src/codec/compressed/stream.rs | 29 ++++++++----------- adder-codec-core/src/codec/empty/stream.rs | 2 +- adder-codec-core/src/codec/encoder.rs | 2 +- adder-codec-core/src/codec/mod.rs | 2 +- adder-codec-core/src/codec/raw/stream.rs | 2 +- adder-codec-core/src/lib.rs | 4 +-- adder-codec-rs/benches/framed_to_adder_hd.rs | 1 - adder-codec-rs/src/bin/adder_to_framed.rs | 17 ++--------- adder-codec-rs/src/framer/scale_intensity.rs | 14 ++++----- adder-codec-rs/src/utils/logging.rs | 1 - adder-codec-rs/src/utils/viz.rs | 2 +- adder-to-dvs/src/main.rs | 25 ++++++++-------- .../src/model/fixed_length.rs | 4 ++- .../src/model/max_length.rs | 4 ++- .../src/model/one_shot.rs | 4 ++- .../benches/common/mod.rs | 3 +- .../examples/concatenated.rs | 1 - .../examples/max_length.rs | 1 - arithmetic-coding-adder-dep/src/decoder.rs | 23 +++++---------- .../tests/concatenated.rs | 1 - .../tests/fixed_length.rs | 1 - .../tests/max_length.rs | 1 - 23 files changed, 57 insertions(+), 88 deletions(-) diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 30256136..aa650a13 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -1,4 +1,5 @@ rustup install nightly +rustup component add clippy sudo apt-get update && sudo apt-get install -y \ clang \ libavdevice-dev \ diff --git a/adder-codec-core/src/codec/compressed/stream.rs b/adder-codec-core/src/codec/compressed/stream.rs index 92bb9688..83a8a7db 100644 --- a/adder-codec-core/src/codec/compressed/stream.rs +++ b/adder-codec-core/src/codec/compressed/stream.rs @@ -3,13 +3,11 @@ use bitstream_io::{BigEndian, BitRead, BitReader, BitWrite, BitWriter}; use priority_queue::PriorityQueue; use std::cmp::Reverse; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; -use std::ops::{Add, AddAssign}; use std::sync::{Arc, RwLock}; use crate::codec::compressed::source_model::event_structure::event_adu::EventAdu; use crate::codec::compressed::source_model::HandleEvent; use crate::codec::header::{Magic, MAGIC_COMPRESSED}; -use crate::codec::rate_controller::CrfParameters; use crate::{DeltaT, Event}; /// A message to send to the writer thread (that is, the main thread) to write out the compressed @@ -71,7 +69,7 @@ pub struct CompressedInput { // } fn flush_bytes_queue_worker( - mut stream: Arc>>, + stream: Arc>>, written_bytes_rx: std::sync::mpsc::Receiver, last_message_written: Arc>, mut bytes_writer_queue: PriorityQueue, Reverse>, @@ -105,7 +103,7 @@ fn flush_bytes_queue_worker( impl CompressedOutput { /// Create a new compressed output stream. pub fn new(meta: CodecMetadata, writer: W) -> Self { - let adu = EventAdu::new(meta.plane, 0, meta.ref_interval, meta.adu_interval as usize); + let adu = EventAdu::new(meta.plane, 0, meta.ref_interval, meta.adu_interval); let (written_bytes_tx, written_bytes_rx) = std::sync::mpsc::channel(); let stream_lock = RwLock::new(BitWriter::endian(writer, BigEndian)); @@ -175,7 +173,7 @@ impl Option { + fn into_writer(mut self) -> Option { if !self.adu.skip_adu { // while self.last_message_sent // != self.last_message_written + self.bytes_writer_queue.len() as u32 @@ -203,7 +201,7 @@ impl start_t + dt_ref * num_intervals as u32 { + if 280 + counter > start_t + dt_ref * num_intervals { break; } else { counter += 1; @@ -552,14 +550,14 @@ mod tests { for x in 0..16 { let event = Event { coord: Coord { x, y, c: None }, - t: min(280 + counter, start_t + dt_ref * num_intervals as u32), + t: min(280 + counter, start_t + dt_ref * num_intervals), d: 7, }; if y == candidate_px_idx.0 && x == candidate_px_idx.1 { input_px_events.push(event); } compressed_output.ingest_event(event).unwrap(); - if 280 + counter > start_t + dt_ref * num_intervals as u32 { + if 280 + counter > start_t + dt_ref * num_intervals { break; } else { counter += 1; @@ -575,7 +573,7 @@ mod tests { y: 0, c: None, }, - t: start_t + dt_ref * num_intervals as u32 + 1, + t: start_t + dt_ref * num_intervals + 1, d: 7, }) .unwrap(); @@ -591,11 +589,8 @@ mod tests { // Check that the size is less than the raw events assert!((output.len() as u32) < counter * 9); - let mut compressed_input = CompressedInput::new( - dt_ref * num_intervals as u32, - dt_ref, - num_intervals as usize, - ); + let mut compressed_input = + CompressedInput::new(dt_ref * num_intervals, dt_ref, num_intervals as usize); compressed_input.meta.plane = plane; let mut stream = BitReader::endian(Cursor::new(output), BigEndian); for i in 0..counter - 1 { diff --git a/adder-codec-core/src/codec/empty/stream.rs b/adder-codec-core/src/codec/empty/stream.rs index abd97480..998c0090 100644 --- a/adder-codec-core/src/codec/empty/stream.rs +++ b/adder-codec-core/src/codec/empty/stream.rs @@ -44,7 +44,7 @@ impl WriteC Ok(()) } - fn into_writer(&mut self) -> Option { + fn into_writer(self) -> Option { None } diff --git a/adder-codec-core/src/codec/encoder.rs b/adder-codec-core/src/codec/encoder.rs index b775e413..2a82478b 100644 --- a/adder-codec-core/src/codec/encoder.rs +++ b/adder-codec-core/src/codec/encoder.rs @@ -149,7 +149,7 @@ impl Encoder { } /// Close the encoder's writer and return it, consuming the encoder in the process. - pub fn close_writer(mut self) -> Result, CodecError> { + pub fn close_writer(self) -> Result, CodecError> { // self.output.byte_align()?; // self.write_eof()?; // self.flush_writer()?; diff --git a/adder-codec-core/src/codec/mod.rs b/adder-codec-core/src/codec/mod.rs index 150a0107..f6c9ace4 100644 --- a/adder-codec-core/src/codec/mod.rs +++ b/adder-codec-core/src/codec/mod.rs @@ -132,7 +132,7 @@ pub trait WriteCompression io::Result<()>; /// Consumes the compression stream and returns the underlying writer. - fn into_writer(&mut self) -> Option; + fn into_writer(self) -> Option; /// Flush the `BitWriter`. Does not flush the internal `BufWriter`. fn flush_writer(&mut self) -> io::Result<()>; diff --git a/adder-codec-core/src/codec/raw/stream.rs b/adder-codec-core/src/codec/raw/stream.rs index 49060db4..70bd0841 100644 --- a/adder-codec-core/src/codec/raw/stream.rs +++ b/adder-codec-core/src/codec/raw/stream.rs @@ -76,7 +76,7 @@ impl WriteCompressio } // If `self.writer` is a `BufWriter`, you'll need to flush it yourself after this. - fn into_writer(&mut self) -> Option { + fn into_writer(mut self) -> Option { let eof = Event { coord: Coord { x: EOF_PX_ADDRESS, diff --git a/adder-codec-core/src/lib.rs b/adder-codec-core/src/lib.rs index dba56401..33c65cf0 100644 --- a/adder-codec-core/src/lib.rs +++ b/adder-codec-core/src/lib.rs @@ -511,8 +511,8 @@ pub struct EventCoordlessRelative { pub delta_t: DeltaT, } -impl Into for EventCoordless { - fn into(self) -> f64 { +impl From for f64 { + fn from(val: EventCoordless) -> Self { panic!("Not implemented") } } diff --git a/adder-codec-rs/benches/framed_to_adder_hd.rs b/adder-codec-rs/benches/framed_to_adder_hd.rs index 6d9faf3c..70502eee 100644 --- a/adder-codec-rs/benches/framed_to_adder_hd.rs +++ b/adder-codec-rs/benches/framed_to_adder_hd.rs @@ -13,7 +13,6 @@ use std::path::PathBuf; use adder_codec_core::TimeMode::DeltaT; use adder_codec_rs::transcoder::source::framed::Framed; -use adder_codec_rs::transcoder::source::video::VideoBuilder; use adder_codec_rs::utils::viz::download_file; use std::thread::sleep; use std::time::Duration; diff --git a/adder-codec-rs/src/bin/adder_to_framed.rs b/adder-codec-rs/src/bin/adder_to_framed.rs index 5c3b7a24..9f337c61 100644 --- a/adder-codec-rs/src/bin/adder_to_framed.rs +++ b/adder-codec-rs/src/bin/adder_to_framed.rs @@ -1,24 +1,13 @@ -use adder_codec_core::codec::compressed::stream::CompressedInput; -use adder_codec_core::codec::decoder::Decoder; -use adder_codec_core::codec::rate_controller::Crf; -use adder_codec_core::codec::raw::stream::RawInput; -use adder_codec_core::codec::{EncoderOptions, EncoderType}; -use adder_codec_core::SourceCamera::{DavisU8, Dvs, FramedU8}; +use adder_codec_core::open_file_decoder; use adder_codec_core::SourceType::U8; -use adder_codec_core::{open_file_decoder, PixelMultiMode, TimeMode}; use adder_codec_rs::framer::driver::FramerMode::INSTANTANEOUS; use adder_codec_rs::framer::driver::{FrameSequence, Framer, FramerBuilder}; -use adder_codec_rs::transcoder::source::prophesee::Prophesee; -use adder_codec_rs::transcoder::source::video::SourceError; -use adder_codec_rs::utils::viz::ShowFeatureMode; -use bitstream_io::{BigEndian, BitReader}; use clap::Parser; use std::fs::File; use std::io; -use std::io::{BufReader, BufWriter, Write}; +use std::io::{BufWriter, Write}; use std::process::Command; use std::time::Instant; -use video_rs_adder_dep::Locator; #[derive(Parser, Debug, Default, serde::Deserialize)] #[clap(author, version, about, long_about = None)] @@ -59,7 +48,7 @@ pub struct MyArgs { #[tokio::main] async fn main() -> Result<(), Box> { - let mut args: MyArgs = MyArgs::parse(); + let args: MyArgs = MyArgs::parse(); // Set up the adder file reader let (mut reader, mut bitreader) = open_file_decoder(&args.input)?; diff --git a/adder-codec-rs/src/framer/scale_intensity.rs b/adder-codec-rs/src/framer/scale_intensity.rs index 232e94a6..98ad0b0f 100644 --- a/adder-codec-rs/src/framer/scale_intensity.rs +++ b/adder-codec-rs/src/framer/scale_intensity.rs @@ -68,7 +68,7 @@ impl FrameValue for u8 { FramedViewMode::Intensity => { let intensity = event_to_intensity(event); match source_type { - SourceType::U8 => ((intensity * tpf)) as u8, + SourceType::U8 => (intensity * tpf) as u8, SourceType::U16 => { (intensity / f64::from(u16::MAX) * tpf * f64::from(u8::MAX)) as u8 } @@ -125,13 +125,11 @@ impl FrameValue for u16 { let intensity = event_to_intensity(event); match source_type { SourceType::U8 => { - (intensity / f64::from(u8::MAX) * tpf * f64::from(u16::MAX)) - as u16 + (intensity / f64::from(u8::MAX) * tpf * f64::from(u16::MAX)) as u16 } SourceType::U16 => (intensity * tpf) as u16, SourceType::U32 => { - (intensity / f64::from(u32::MAX) * tpf * f64::from(u16::MAX)) - as u16 + (intensity / f64::from(u32::MAX) * tpf * f64::from(u16::MAX)) as u16 } SourceType::U64 => { (intensity / u64::MAX as f64 * tpf * f64::from(u16::MAX)) as u16 @@ -178,12 +176,10 @@ impl FrameValue for u32 { let intensity = event_to_intensity(event); match source_type { SourceType::U8 => { - (intensity / f64::from(u8::MAX) * tpf * f64::from(u32::MAX)) - as u32 + (intensity / f64::from(u8::MAX) * tpf * f64::from(u32::MAX)) as u32 } SourceType::U16 => { - (intensity / f64::from(u16::MAX) * tpf * f64::from(u32::MAX)) - as u32 + (intensity / f64::from(u16::MAX) * tpf * f64::from(u32::MAX)) as u32 } SourceType::U32 => (intensity * tpf) as u32, SourceType::U64 => { diff --git a/adder-codec-rs/src/utils/logging.rs b/adder-codec-rs/src/utils/logging.rs index 1e2ca39e..ed48eacb 100644 --- a/adder-codec-rs/src/utils/logging.rs +++ b/adder-codec-rs/src/utils/logging.rs @@ -1,4 +1,3 @@ - use adder_codec_core::Coord; use opencv::core::KeyPoint; use serde::ser::SerializeStruct; diff --git a/adder-codec-rs/src/utils/viz.rs b/adder-codec-rs/src/utils/viz.rs index 467d2baa..bf4be475 100644 --- a/adder-codec-rs/src/utils/viz.rs +++ b/adder-codec-rs/src/utils/viz.rs @@ -9,7 +9,7 @@ use std::io::BufWriter; use std::io::{Cursor, Write}; use std::path::Path; use std::process::{Command, Output}; -use video_rs_adder_dep::{Frame}; +use video_rs_adder_dep::Frame; #[cfg(feature = "open-cv")] /// Writes a given [`Mat`] to a file diff --git a/adder-to-dvs/src/main.rs b/adder-to-dvs/src/main.rs index 6409fac8..a5b3bc2d 100644 --- a/adder-to-dvs/src/main.rs +++ b/adder-to-dvs/src/main.rs @@ -1,6 +1,6 @@ use adder_codec_core::codec::CodecMetadata; use adder_codec_core::*; -use chrono::{DateTime, Local}; +use chrono::Local; use clap::{Parser, ValueEnum}; use ndarray::Array3; use serde::{Deserialize, Serialize}; @@ -11,7 +11,6 @@ use std::fs::File; use std::io::{BufWriter, Write}; use std::option::Option; use std::path::PathBuf; -use std::time::Instant; use std::{error, io}; use video_rs::{Encoder, EncoderSettings, Options, PixelFormat}; @@ -149,18 +148,18 @@ fn main() -> Result<(), Box> { // .write(dims_str.as_ref()) // .expect("Could not write"); - write!(output_events_writer, "% Height {}\n", meta.plane.h())?; - write!(output_events_writer, "% Width {}\n", meta.plane.w())?; - write!(output_events_writer, "% Version 2\n")?; + writeln!(output_events_writer, "% Height {}", meta.plane.h())?; + writeln!(output_events_writer, "% Width {}", meta.plane.w())?; + writeln!(output_events_writer, "% Version 2")?; // Write the date and time let now = Local::now(); let date_time_str = now.format("%Y-%m-%d %H:%M:%S").to_string(); - write!(output_events_writer, "% Date {}\n", date_time_str)?; - write!(output_events_writer, "% end\n")?; + writeln!(output_events_writer, "% Date {}", date_time_str)?; + writeln!(output_events_writer, "% end")?; if args.output_mode == WriteMode::Binary { let event_type_size: [u8; 2] = [0, 8]; - output_events_writer.write(&event_type_size)?; + output_events_writer.write_all(&event_type_size)?; } } @@ -434,7 +433,7 @@ fn set_instant_dvs_pixel( let grow_len = frame_idx as i32 - frame_count as i32 - frames.len() as i32 + 1; for _ in 0..grow_len { - frames.push_back(create_blank_dvs_frame(&meta)?); + frames.push_back(create_blank_dvs_frame(meta)?); } if frame_idx >= frame_count { @@ -472,7 +471,7 @@ pub fn write_frame_to_video( encoder: &mut video_rs::Encoder, timestamp: video_rs::Time, ) -> Result<(), Box> { - encoder.encode(&frame, ×tamp).map_err(|e| e.into()) + encoder.encode(frame, ×tamp).map_err(|e| e.into()) } fn fire_dvs_event( @@ -502,8 +501,8 @@ fn fire_dvs_event( WriteMode::Binary => { let event = DvsEvent { t: t as u32, - x: x as u16, - y: y as u16, + x, + y, p: if polarity { 1 } else { 0 }, }; @@ -535,7 +534,7 @@ fn write_event_binary(event: &DvsEvent, writer: &mut BufWriter) -> io::Res let mut buffer = [0; 8]; // t as u32 into the first four bytes of the buffer - buffer[0..4].copy_from_slice(&(event.t as u32).to_le_bytes()); + buffer[0..4].copy_from_slice(&(event.t).to_le_bytes()); let mut data: u32 = 0; diff --git a/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/fixed_length.rs b/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/fixed_length.rs index ba2a51a7..0b38c3cc 100644 --- a/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/fixed_length.rs +++ b/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/fixed_length.rs @@ -5,7 +5,9 @@ use std::ops::Range; use crate::BitStore; /// A [`Model`] is used to calculate the probability of a given symbol occuring -/// in a sequence. The [`Model`] is used both for encoding and decoding. A +/// in a sequence. +/// +/// The [`Model`] is used both for encoding and decoding. A /// 'fixed-length' model always expects an exact number of symbols, and so does /// not need to encode an EOF symbol. /// diff --git a/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/max_length.rs b/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/max_length.rs index 9c45eea1..477a5038 100644 --- a/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/max_length.rs +++ b/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/max_length.rs @@ -5,7 +5,9 @@ use std::ops::Range; use crate::BitStore; /// A [`Model`] is used to calculate the probability of a given symbol occuring -/// in a sequence. The [`Model`] is used both for encoding and decoding. A +/// in a sequence. +/// +/// The [`Model`] is used both for encoding and decoding. A /// 'max-length' model has a maximum length. The compressed size of a message /// equal to the maximum length is larger than with a /// [`fixed_length::Model`](crate::fixed_length::Model), but smaller than with a diff --git a/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/one_shot.rs b/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/one_shot.rs index 13529f1e..d7d10a44 100644 --- a/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/one_shot.rs +++ b/arithmetic-coding-adder-dep/arithmetic-coding-core-adder-dep/src/model/one_shot.rs @@ -6,7 +6,9 @@ pub use crate::fixed_length::Wrapper; use crate::{fixed_length, BitStore}; /// A [`Model`] is used to calculate the probability of a given symbol occuring -/// in a sequence. The [`Model`] is used both for encoding and decoding. A +/// in a sequence. +/// +/// The [`Model`] is used both for encoding and decoding. A /// 'fixed-length' model always expects an exact number of symbols, and so does /// not need to encode an EOF symbol. /// diff --git a/arithmetic-coding-adder-dep/benches/common/mod.rs b/arithmetic-coding-adder-dep/benches/common/mod.rs index 1342b364..44182ced 100644 --- a/arithmetic-coding-adder-dep/benches/common/mod.rs +++ b/arithmetic-coding-adder-dep/benches/common/mod.rs @@ -1,5 +1,4 @@ -use arithmetic_coding_adder_dep::{Model}; - +use arithmetic_coding_adder_dep::Model; pub fn round_trip(model: M, input: &[M::Symbol]) where diff --git a/arithmetic-coding-adder-dep/examples/concatenated.rs b/arithmetic-coding-adder-dep/examples/concatenated.rs index 216e276b..e8144894 100644 --- a/arithmetic-coding-adder-dep/examples/concatenated.rs +++ b/arithmetic-coding-adder-dep/examples/concatenated.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] #![feature(never_type)] use arithmetic_coding_adder_dep::{Decoder, Encoder, Model}; diff --git a/arithmetic-coding-adder-dep/examples/max_length.rs b/arithmetic-coding-adder-dep/examples/max_length.rs index 2183cf5e..6cfe3a21 100644 --- a/arithmetic-coding-adder-dep/examples/max_length.rs +++ b/arithmetic-coding-adder-dep/examples/max_length.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] #![feature(never_type)] use std::ops::Range; diff --git a/arithmetic-coding-adder-dep/src/decoder.rs b/arithmetic-coding-adder-dep/src/decoder.rs index 31478254..71131e47 100644 --- a/arithmetic-coding-adder-dep/src/decoder.rs +++ b/arithmetic-coding-adder-dep/src/decoder.rs @@ -104,7 +104,7 @@ where /// Return an iterator over the decoded symbols. /// /// The iterator will continue returning symbols until EOF is reached - pub fn decode_all<'a>(&'a mut self, input: &'a mut R) -> DecodeIter { + pub fn decode_all<'a>(&'a mut self, input: &'a mut R) -> DecodeIter<'a, M, R> { DecodeIter { decoder: self, input, @@ -245,11 +245,8 @@ where self.x = (self.x - self.half()) << 1; } - match input.next_bit()? { - Some(true) => { - self.x += B::ONE; - } - Some(false) | None => (), + if let Some(true) = input.next_bit()? { + self.x += B::ONE; } } @@ -258,11 +255,8 @@ where self.high = (self.high - self.quarter()) << 1; self.x = (self.x - self.quarter()) << 1; - match input.next_bit()? { - Some(true) => { - self.x += B::ONE; - } - Some(false) | None => (), + if let Some(true) = input.next_bit()? { + self.x += B::ONE; } } @@ -286,11 +280,8 @@ where fn fill(&mut self, input: &mut R) -> io::Result<()> { for _ in 0..self.precision { self.x <<= 1; - match input.next_bit()? { - Some(true) => { - self.x += B::ONE; - } - Some(false) | None => (), + if let Some(true) = input.next_bit()? { + self.x += B::ONE; } } Ok(()) diff --git a/arithmetic-coding-adder-dep/tests/concatenated.rs b/arithmetic-coding-adder-dep/tests/concatenated.rs index 54fcbcef..bfb02a7e 100644 --- a/arithmetic-coding-adder-dep/tests/concatenated.rs +++ b/arithmetic-coding-adder-dep/tests/concatenated.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] #![feature(never_type)] use arithmetic_coding_adder_dep::{Decoder, Encoder, Model}; diff --git a/arithmetic-coding-adder-dep/tests/fixed_length.rs b/arithmetic-coding-adder-dep/tests/fixed_length.rs index 5401fbfd..322a5d2c 100644 --- a/arithmetic-coding-adder-dep/tests/fixed_length.rs +++ b/arithmetic-coding-adder-dep/tests/fixed_length.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] #![feature(never_type)] use std::ops::Range; diff --git a/arithmetic-coding-adder-dep/tests/max_length.rs b/arithmetic-coding-adder-dep/tests/max_length.rs index 4d691a5f..1ba5761d 100644 --- a/arithmetic-coding-adder-dep/tests/max_length.rs +++ b/arithmetic-coding-adder-dep/tests/max_length.rs @@ -1,4 +1,3 @@ -#![feature(exclusive_range_pattern)] #![feature(never_type)] use std::ops::Range;