Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Fix compiler and clippy warnings #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/buffer/std_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
33 changes: 20 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ impl<R: Read, P> BufReader<R, P> {
}

/// Box the inner reader without losing data.
pub fn boxed<'a>(self) -> BufReader<Box<Read + 'a>, P> where R: 'a {
let inner: Box<Read + 'a> = Box::new(self.inner);
pub fn boxed<'a>(self) -> BufReader<Box<dyn Read + 'a>, P> where R: 'a {
let inner: Box<dyn Read + 'a> = Box::new(self.inner);

BufReader {
inner,
buf: self.buf,
Expand Down Expand Up @@ -868,7 +868,7 @@ impl<W: Any + Send + fmt::Debug> error::Error for IntoInnerError<W> {
error::Error::description(self.error())
}

fn cause(&self) -> Option<&error::Error> {
fn cause(&self) -> Option<&dyn error::Error> {
Some(&self.1)
}
}
Expand Down Expand Up @@ -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)?
};

Expand All @@ -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
Expand All @@ -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<W: Write + ?Sized>(&mut self, wrt: &mut W) -> io::Result<usize> {
if self.len() == 0 {
if self.is_empty() {
return Ok(0);
}

Expand All @@ -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<W: Write + ?Sized>(&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,
Expand All @@ -1125,7 +1125,7 @@ impl Buffer {
/// ### Panics
/// If `self.write_to(wrt)` panics.
pub fn write_all<W: Write + ?Sized>(&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")),
Expand Down Expand Up @@ -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")
Expand All @@ -1201,7 +1207,7 @@ pub struct Unbuffer<R> {
impl<R> Unbuffer<R> {
/// 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.
Expand All @@ -1225,7 +1231,7 @@ impl<R: Read> Read for Unbuffer<R> {
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);
}
}
Expand Down Expand Up @@ -1270,7 +1276,8 @@ pub fn copy_buf<B: BufRead, W: Write>(b: &mut B, w: &mut W) -> io::Result<u64> {
}

thread_local!(
static DROP_ERR_HANDLER: RefCell<Box<Fn(&mut Write, &mut Buffer, io::Error)>>
#[allow(clippy::type_complexity)]
static DROP_ERR_HANDLER: RefCell<Box<dyn Fn(&mut dyn Write, &mut Buffer, io::Error)>>
= RefCell::new(Box::new(|_, _, _| ()))
);

Expand All @@ -1283,7 +1290,7 @@ thread_local!(
/// ### Panics
/// If called from within a handler previously provided to this function.
pub fn set_drop_err_handler<F: 'static>(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))
}
Expand Down
2 changes: 1 addition & 1 deletion src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down