From eca48bb93feec160ba57654bf709127806ba5c99 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hiler Date: Fri, 4 Nov 2022 14:41:27 +0200 Subject: [PATCH] media-converter: Apply `cargo clippy` suggestions. --- media-converter/src/audioconv/imp.rs | 6 +++--- media-converter/src/fossilize.rs | 28 ++++++++++++---------------- media-converter/src/lib.rs | 4 ++-- media-converter/src/videoconv/imp.rs | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/media-converter/src/audioconv/imp.rs b/media-converter/src/audioconv/imp.rs index 3c24ef6e..4103f10b 100644 --- a/media-converter/src/audioconv/imp.rs +++ b/media-converter/src/audioconv/imp.rs @@ -300,7 +300,7 @@ static DUMPING_DISABLED: Lazy = Lazy::new(|| { Err(_) => { return false; }, Ok(c) => c, }; - return v != "0"; + v != "0" }); #[derive(Clone)] @@ -770,7 +770,7 @@ impl ElementImpl for AudioConv { let new_state = AudioConvState::new().map_err(|err| { err.log(); - return gst::StateChangeError; + gst::StateChangeError })?; let mut state = self.state.lock().unwrap(); @@ -887,7 +887,7 @@ impl AudioConv { let mut state = self.state.lock().unwrap(); if let Some(state) = &mut *state { - let head = match NeedTranscodeHead::new_from_caps(&event_caps.caps()){ + let head = match NeedTranscodeHead::new_from_caps(event_caps.caps()){ Ok(h) => h, Err(e) => { gst::error!(CAT, "Invalid WMA caps!"); diff --git a/media-converter/src/fossilize.rs b/media-converter/src/fossilize.rs index a52104ff..8e9ab966 100644 --- a/media-converter/src/fossilize.rs +++ b/media-converter/src/fossilize.rs @@ -95,7 +95,7 @@ const _FOSSILIZE_COMPRESSION_DEFLATE: u32 = 2; #[derive(Debug)] pub enum Error { NotImplemented, - IOError(io::Error), + IO(io::Error), CorruptDatabase, DataTooLarge, InvalidTag, @@ -105,7 +105,7 @@ pub enum Error { impl From for Error { fn from(e: io::Error) -> Error { - Error::IOError(e) + Error::IO(e) } } @@ -240,9 +240,7 @@ impl StreamArchive { let version = magic_and_version[15]; - if magic_and_version[0..12] != FOSSILIZE_MAGIC || - version < FOSSILIZE_MIN_COMPAT_VERSION || - version > FOSSILIZE_VERSION { + if magic_and_version[0..12] != FOSSILIZE_MAGIC || !(FOSSILIZE_MIN_COMPAT_VERSION..=FOSSILIZE_VERSION).contains(&version) { return Err(Error::CorruptDatabase); } @@ -256,7 +254,7 @@ impl StreamArchive { if fail.kind() == io::ErrorKind::UnexpectedEof { break; } - return Err(Error::IOError(fail)); + return Err(Error::IO(fail)); } let name = &name_and_header[0..PAYLOAD_NAME_LEN_BYTES]; @@ -283,7 +281,7 @@ impl StreamArchive { Err(e) => { /* truncated chunk is not fatal */ if e.kind() != io::ErrorKind::UnexpectedEof { - return Err(Error::IOError(e)); + return Err(Error::IO(e)); } }, } @@ -339,7 +337,7 @@ impl StreamArchive { let to_copy = std::cmp::min(entry.payload_info.full_size as usize - offset as usize, buf.len()); self.file.read_exact(&mut buf[0..to_copy]) - .map_err(Error::IOError)?; + .map_err(Error::IO)?; if entry.payload_info.crc != 0 { if let CRCCheck::WithCRC = crc_opt { @@ -434,20 +432,18 @@ impl StreamArchive { } /* rewrites the database, discarding entries listed in 'to_discard' */ - pub fn discard_entries(&mut self, to_discard: &Vec<(FossilizeTag, FossilizeHash)>) -> Result<(), Error> { + pub fn discard_entries(&mut self, to_discard: &[(FossilizeTag, FossilizeHash)]) -> Result<(), Error> { self.write_pos = self.file.seek(io::SeekFrom::Start(0))?; for v in self.seen_blobs.iter_mut() { v.clear(); } - let mut magic_and_version = [0 as u8; MAGIC_LEN_BYTES]; + let mut magic_and_version = [0_u8; MAGIC_LEN_BYTES]; self.file.read_exact(&mut magic_and_version)?; let version = magic_and_version[15]; - if magic_and_version[0..12] != FOSSILIZE_MAGIC || - version < FOSSILIZE_MIN_COMPAT_VERSION || - version > FOSSILIZE_VERSION { + if magic_and_version[0..12] != FOSSILIZE_MAGIC || !(FOSSILIZE_MIN_COMPAT_VERSION..=FOSSILIZE_VERSION).contains(&version) { return Err(Error::CorruptDatabase); } @@ -461,7 +457,7 @@ impl StreamArchive { if fail.kind() == io::ErrorKind::UnexpectedEof { break; } - return Err(Error::IOError(fail)); + return Err(Error::IO(fail)); } let name = &name_and_header[0..PAYLOAD_NAME_LEN_BYTES]; @@ -484,7 +480,7 @@ impl StreamArchive { Err(e) => { /* truncated chunk is not fatal */ if e.kind() != io::ErrorKind::UnexpectedEof { - return Err(Error::IOError(e)); + return Err(Error::IO(e)); } }, } @@ -501,7 +497,7 @@ impl StreamArchive { Err(e) => { /* truncated chunk is not fatal */ if e.kind() != io::ErrorKind::UnexpectedEof { - return Err(Error::IOError(e)); + return Err(Error::IO(e)); } }, } diff --git a/media-converter/src/lib.rs b/media-converter/src/lib.rs index c3ed7e8e..59d48160 100644 --- a/media-converter/src/lib.rs +++ b/media-converter/src/lib.rs @@ -97,7 +97,7 @@ macro_rules! box_array { /* you MUST use this to consistently format the hash bytes into a string */ fn format_hash(hash: u128) -> String { - return format!("{:032x}", hash); + format!("{:032x}", hash) } /* changing this will invalidate the cache. you MUST clear it. */ @@ -144,7 +144,7 @@ fn discarding_disabled() -> bool { Err(_) => { return false; }, Ok(c) => c, }; - return v != "0"; + v != "0" } fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { diff --git a/media-converter/src/videoconv/imp.rs b/media-converter/src/videoconv/imp.rs index 6045ab03..2a170d37 100644 --- a/media-converter/src/videoconv/imp.rs +++ b/media-converter/src/videoconv/imp.rs @@ -499,7 +499,7 @@ impl ElementImpl for VideoConv { let new_state = VideoConvState::new().map_err(|err| { err.log(); - return gst::StateChangeError; + gst::StateChangeError })?; let mut state = self.state.lock().unwrap();