diff --git a/src/buffer/std_buf.rs b/src/buffer/std_buf.rs index 7e717c3..95adbfd 100644 --- a/src/buffer/std_buf.rs +++ b/src/buffer/std_buf.rs @@ -160,7 +160,7 @@ mod impl_ { pub fn reserve_in_place(&mut self, _additional: usize) -> bool { // `Vec` does not support this - return false; + false } pub unsafe fn as_slice(&self) -> &[u8] { diff --git a/src/lib.rs b/src/lib.rs index 6a5365a..f58dcc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -370,9 +370,9 @@ impl BufReader { } /// Box the inner reader without losing data. - pub fn boxed<'a>(self) -> BufReader, P> where R: 'a { - let inner: Box = Box::new(self.inner); - + pub fn boxed<'a>(self) -> BufReader, P> where R: 'a { + let inner: Box = Box::new(self.inner); + BufReader { inner, buf: self.buf, @@ -868,7 +868,7 @@ impl error::Error for IntoInnerError { error::Error::description(self.error()) } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { Some(&self.1) } } @@ -1047,7 +1047,7 @@ impl Buffer { } let read = { - let mut buf = unsafe { self.buf.write_buf() }; + let buf = unsafe { self.buf.write_buf() }; rdr.read(buf)? }; @@ -1065,7 +1065,7 @@ impl Buffer { /// space, this returns 0. pub fn copy_from_slice(&mut self, src: &[u8]) -> usize { let len = unsafe { - let mut buf = self.buf.write_buf(); + let buf = self.buf.write_buf(); let len = cmp::min(buf.len(), src.len()); buf[..len].copy_from_slice(&src[..len]); len @@ -1086,7 +1086,7 @@ impl Buffer { /// If the count returned by `wrt.write()` would cause the head cursor to overflow or pass /// the tail cursor if added to it. pub fn write_to(&mut self, wrt: &mut W) -> io::Result { - if self.len() == 0 { + if self.is_empty() { return Ok(0); } @@ -1102,7 +1102,7 @@ impl Buffer { /// If the count returned by `wrt.write()` would cause the head cursor to overflow or pass /// the tail cursor if added to it. pub fn write_max(&mut self, mut max: usize, wrt: &mut W) -> io::Result<()> { - while self.len() > 0 && max > 0 { + while !self.is_empty() && max > 0 { let len = cmp::min(self.len(), max); let n = match wrt.write(&self.buf()[..len]) { Ok(0) => return Err(io::Error::new(io::ErrorKind::WriteZero, @@ -1125,7 +1125,7 @@ impl Buffer { /// ### Panics /// If `self.write_to(wrt)` panics. pub fn write_all(&mut self, wrt: &mut W) -> io::Result<()> { - while self.len() > 0 { + while !self.is_empty() { match self.write_to(wrt) { Ok(0) => return Err(io::Error::new(io::ErrorKind::WriteZero, "Buffer::write_all() got zero-sized write")), @@ -1182,6 +1182,12 @@ impl Buffer { } } +impl Default for Buffer { + fn default() -> Self { + Buffer::new() + } +} + impl fmt::Debug for Buffer { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("buf_redux::Buffer") @@ -1201,7 +1207,7 @@ pub struct Unbuffer { impl Unbuffer { /// Returns `true` if the buffer still has some bytes left, `false` otherwise. pub fn is_buf_empty(&self) -> bool { - !self.buf.is_some() + self.buf.is_none() } /// Returns the number of bytes remaining in the buffer. @@ -1225,7 +1231,7 @@ impl Read for Unbuffer { if let Some(ref mut buf) = self.buf.as_mut() { let read = buf.copy_to_slice(out); - if out.len() != 0 && read != 0 { + if !out.is_empty() && read != 0 { return Ok(read); } } @@ -1270,7 +1276,8 @@ pub fn copy_buf(b: &mut B, w: &mut W) -> io::Result { } thread_local!( - static DROP_ERR_HANDLER: RefCell> + #[allow(clippy::type_complexity)] + static DROP_ERR_HANDLER: RefCell> = RefCell::new(Box::new(|_, _, _| ())) ); @@ -1283,7 +1290,7 @@ thread_local!( /// ### Panics /// If called from within a handler previously provided to this function. pub fn set_drop_err_handler(handler: F) -where F: Fn(&mut Write, &mut Buffer, io::Error) +where F: Fn(&mut dyn Write, &mut Buffer, io::Error) { DROP_ERR_HANDLER.with(|deh| *deh.borrow_mut() = Box::new(handler)) } diff --git a/src/policy.rs b/src/policy.rs index c2ab54b..45a05f8 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -55,7 +55,7 @@ pub trait ReaderPolicy { /// If the read will ignore the buffer entirely (if the buffer is empty and the amount to be /// read matches or exceeds its capacity) or if `BufReader::read_into_buf()` was called to force /// a read into the buffer manually, this method will not be called. - fn before_read(&mut self, buffer: &mut Buffer) -> DoRead { DoRead(buffer.len() == 0) } + fn before_read(&mut self, buffer: &mut Buffer) -> DoRead { DoRead(buffer.is_empty()) } /// Called after bytes are consumed from the buffer. ///