diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-15 02:36:32 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-15 02:36:32 -0500 |
commit | 3e0b4e415b99f9324cc0e25c71444d73dbff869f (patch) | |
tree | 54e1324c8620aeacd6807377f21b5233d39e7942 | |
parent | 75d44755bdd5da61e6409fa739e333b1e2b9a1da (diff) | |
download | ttyrec-3e0b4e415b99f9324cc0e25c71444d73dbff869f.tar.gz ttyrec-3e0b4e415b99f9324cc0e25c71444d73dbff869f.zip |
be a bit less aggressive
-rw-r--r-- | src/blocking/reader.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/parser.rs | 42 | ||||
-rw-r--r-- | src/reader.rs | 4 |
4 files changed, 23 insertions, 31 deletions
diff --git a/src/blocking/reader.rs b/src/blocking/reader.rs index f4a51a8..ef2f783 100644 --- a/src/blocking/reader.rs +++ b/src/blocking/reader.rs @@ -21,6 +21,8 @@ impl<T: std::io::Read> Reader<T> { /// * [`Error::EOF`](crate::Error::EOF): The input stream has been closed. /// * [`Error::Read`](crate::Error::Read): There was an error reading from /// the input stream. + // these unwraps aren't reachable + #[allow(clippy::missing_panics_doc)] pub fn read_frame(&mut self) -> crate::Result<crate::Frame> { loop { if let Some(frame) = self.parser.next_frame() { @@ -36,7 +38,7 @@ impl<T: std::io::Read> Reader<T> { self.parser.add_bytes( // read() returning a value means that that many bytes are // guaranteed to be available - self.buf.get(..bytes).unwrap_or_else(|| unreachable!()), + &self.buf[..bytes], ); } } @@ -14,10 +14,8 @@ #![warn(clippy::cargo)] #![warn(clippy::pedantic)] #![warn(clippy::nursery)] -#![warn(clippy::unwrap_used)] -#![warn(clippy::expect_used)] -#![warn(clippy::indexing_slicing)] #![warn(clippy::as_conversions)] +#![warn(clippy::get_unwrap)] #![allow(clippy::cognitive_complexity)] #![allow(clippy::missing_const_for_fn)] #![allow(clippy::similar_names)] diff --git a/src/parser.rs b/src/parser.rs index 37c5118..0d65a87 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -52,6 +52,8 @@ impl Parser { /// If a complete frame is found, the bytes for that frame will be removed /// from the internal buffer and the frame object will be returned. If a /// complete frame is not found, this method will return [`None`]. + // these unwraps aren't reachable + #[allow(clippy::missing_panics_doc)] pub fn next_frame(&mut self) -> Option<crate::frame::Frame> { let header = if let Some(header) = &self.read_state { header @@ -61,41 +63,29 @@ impl Parser { } // these unwraps are guaranteed safe by the length check above - let secs1 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let secs2 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let secs3 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let secs4 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); + let secs1 = self.reading.pop_front().unwrap(); + let secs2 = self.reading.pop_front().unwrap(); + let secs3 = self.reading.pop_front().unwrap(); + let secs4 = self.reading.pop_front().unwrap(); let secs = u32::from_le_bytes([secs1, secs2, secs3, secs4]); - let micros1 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let micros2 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let micros3 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let micros4 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); + let micros1 = self.reading.pop_front().unwrap(); + let micros2 = self.reading.pop_front().unwrap(); + let micros3 = self.reading.pop_front().unwrap(); + let micros4 = self.reading.pop_front().unwrap(); let micros = u32::from_le_bytes([micros1, micros2, micros3, micros4]); - let len1 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let len2 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let len3 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); - let len4 = - self.reading.pop_front().unwrap_or_else(|| unreachable!()); + let len1 = self.reading.pop_front().unwrap(); + let len2 = self.reading.pop_front().unwrap(); + let len3 = self.reading.pop_front().unwrap(); + let len4 = self.reading.pop_front().unwrap(); let len = u32::from_le_bytes([len1, len2, len3, len4]); let header = Header { secs, micros, len }; self.read_state = Some(header); // unwrap is safe because we just set self.read_state to Some - self.read_state.as_ref().unwrap_or_else(|| unreachable!()) + self.read_state.as_ref().unwrap() }; if self.reading.len() < header.len() { @@ -107,7 +97,7 @@ impl Parser { data.push( // unwrap is safe because we just checked that there are // sufficient bytes in self.reading - self.reading.pop_front().unwrap_or_else(|| unreachable!()), + self.reading.pop_front().unwrap(), ); } diff --git a/src/reader.rs b/src/reader.rs index 478af36..3426dcb 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -24,6 +24,8 @@ impl<T: futures_lite::io::AsyncRead + std::marker::Unpin + Send> Reader<T> { /// * [`Error::EOF`](crate::Error::EOF): The input stream has been closed. /// * [`Error::Read`](crate::Error::Read): There was an error reading from /// the input stream. + // these unwraps aren't reachable + #[allow(clippy::missing_panics_doc)] pub async fn read_frame(&mut self) -> crate::Result<crate::Frame> { loop { if let Some(frame) = self.parser.next_frame() { @@ -40,7 +42,7 @@ impl<T: futures_lite::io::AsyncRead + std::marker::Unpin + Send> Reader<T> { self.parser.add_bytes( // read() returning a value means that that many bytes are // guaranteed to be available - self.buf.get(..bytes).unwrap_or_else(|| unreachable!()), + &self.buf[..bytes], ); } } |