diff --git a/src/codec/brotli/decoder.rs b/src/codec/brotli/decoder.rs index be115b1..27e19b9 100644 --- a/src/codec/brotli/decoder.rs +++ b/src/codec/brotli/decoder.rs @@ -40,9 +40,7 @@ impl BrotliDecoder { &mut 0, &mut self.state, ) { - BrotliResult::ResultFailure => { - return Err(io::Error::new(io::ErrorKind::Other, "brotli error")) - } + BrotliResult::ResultFailure => return Err(io::Error::other("brotli error")), status => status, }; diff --git a/src/codec/brotli/encoder.rs b/src/codec/brotli/encoder.rs index dc974e3..fe363f9 100644 --- a/src/codec/brotli/encoder.rs +++ b/src/codec/brotli/encoder.rs @@ -41,7 +41,7 @@ impl BrotliEncoder { &mut None, &mut |_, _, _, _| (), ) { - return Err(io::Error::new(io::ErrorKind::Other, "brotli error")); + return Err(io::Error::other("brotli error")); } input.advance(input_len); diff --git a/src/codec/bzip2/decoder.rs b/src/codec/bzip2/decoder.rs index f392a17..255169b 100644 --- a/src/codec/bzip2/decoder.rs +++ b/src/codec/bzip2/decoder.rs @@ -36,7 +36,7 @@ impl BzDecoder { let status = self .decompress .decompress(input.unwritten(), output.unwritten_mut()) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + .map_err(io::Error::other)?; input.advance((self.decompress.total_in() - prior_in) as usize); output.advance((self.decompress.total_out() - prior_out) as usize); @@ -74,7 +74,7 @@ impl Decode for BzDecoder { // There was insufficient memory in the input or output buffer to complete // the request, but otherwise everything went normally. - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "out of memory")), + Status::MemNeeded => Err(io::Error::other("out of memory")), } } diff --git a/src/codec/bzip2/encoder.rs b/src/codec/bzip2/encoder.rs index f17bdbf..3dbfc1c 100644 --- a/src/codec/bzip2/encoder.rs +++ b/src/codec/bzip2/encoder.rs @@ -57,7 +57,7 @@ impl BzEncoder { let status = self .compress .compress(input.unwritten(), output.unwritten_mut(), action) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + .map_err(io::Error::other)?; input.advance((self.compress.total_in() - prior_in) as usize); output.advance((self.compress.total_out() - prior_out) as usize); @@ -90,7 +90,7 @@ impl Encode for BzEncoder { // There was insufficient memory in the input or output buffer to complete // the request, but otherwise everything went normally. - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "out of memory")), + Status::MemNeeded => Err(io::Error::other("out of memory")), } } @@ -116,7 +116,7 @@ impl Encode for BzEncoder { // There was insufficient memory in the input or output buffer to complete // the request, but otherwise everything went normally. - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "out of memory")), + Status::MemNeeded => Err(io::Error::other("out of memory")), } } @@ -142,7 +142,7 @@ impl Encode for BzEncoder { // There was insufficient memory in the input or output buffer to complete // the request, but otherwise everything went normally. - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "out of memory")), + Status::MemNeeded => Err(io::Error::other("out of memory")), } } } diff --git a/src/codec/flate/decoder.rs b/src/codec/flate/decoder.rs index 70c28c2..86fd139 100644 --- a/src/codec/flate/decoder.rs +++ b/src/codec/flate/decoder.rs @@ -51,7 +51,7 @@ impl Decode for FlateDecoder { match self.decode(input, output, FlushDecompress::None)? { Status::Ok => Ok(false), Status::StreamEnd => Ok(true), - Status::BufError => Err(io::Error::new(io::ErrorKind::Other, "unexpected BufError")), + Status::BufError => Err(io::Error::other("unexpected BufError")), } } @@ -91,7 +91,7 @@ impl Decode for FlateDecoder { )? { Status::Ok => Ok(false), Status::StreamEnd => Ok(true), - Status::BufError => Err(io::Error::new(io::ErrorKind::Other, "unexpected BufError")), + Status::BufError => Err(io::Error::other("unexpected BufError")), } } } diff --git a/src/codec/flate/encoder.rs b/src/codec/flate/encoder.rs index 8665b0b..bcf6c02 100644 --- a/src/codec/flate/encoder.rs +++ b/src/codec/flate/encoder.rs @@ -51,7 +51,7 @@ impl Encode for FlateEncoder { match self.encode(input, output, FlushCompress::None)? { Status::Ok => Ok(()), Status::StreamEnd => unreachable!(), - Status::BufError => Err(io::Error::new(io::ErrorKind::Other, "unexpected BufError")), + Status::BufError => Err(io::Error::other("unexpected BufError")), } } @@ -100,7 +100,7 @@ impl Encode for FlateEncoder { )? { Status::Ok => Ok(false), Status::StreamEnd => Ok(true), - Status::BufError => Err(io::Error::new(io::ErrorKind::Other, "unexpected BufError")), + Status::BufError => Err(io::Error::other("unexpected BufError")), } } } diff --git a/src/codec/gzip/encoder.rs b/src/codec/gzip/encoder.rs index 5fcf35c..e6da04a 100644 --- a/src/codec/gzip/encoder.rs +++ b/src/codec/gzip/encoder.rs @@ -72,10 +72,7 @@ impl Encode for GzipEncoder { } State::Footer(_) | State::Done => { - return Err(io::Error::new( - io::ErrorKind::Other, - "encode after complete", - )); + return Err(io::Error::other("encode after complete")); } }; diff --git a/src/codec/gzip/header.rs b/src/codec/gzip/header.rs index 9faa638..ebe482a 100644 --- a/src/codec/gzip/header.rs +++ b/src/codec/gzip/header.rs @@ -156,10 +156,7 @@ impl Parser { } State::Done => { - return Err(io::Error::new( - io::ErrorKind::Other, - "parser used after done", - )); + return Err(io::Error::other("parser used after done")); } }; } diff --git a/src/codec/xz2/decoder.rs b/src/codec/xz2/decoder.rs index cfcd1cb..1c111fd 100644 --- a/src/codec/xz2/decoder.rs +++ b/src/codec/xz2/decoder.rs @@ -46,11 +46,8 @@ impl Decode for Xz2Decoder { match status { Status::Ok => Ok(false), Status::StreamEnd => Ok(true), - Status::GetCheck => Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected lzma integrity check", - )), - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "More memory needed")), + Status::GetCheck => Err(io::Error::other("Unexpected lzma integrity check")), + Status::MemNeeded => Err(io::Error::other("More memory needed")), } } @@ -77,11 +74,8 @@ impl Decode for Xz2Decoder { match status { Status::Ok => Ok(false), Status::StreamEnd => Ok(true), - Status::GetCheck => Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected lzma integrity check", - )), - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "More memory needed")), + Status::GetCheck => Err(io::Error::other("Unexpected lzma integrity check")), + Status::MemNeeded => Err(io::Error::other("More memory needed")), } } } diff --git a/src/codec/xz2/encoder.rs b/src/codec/xz2/encoder.rs index d31070a..f032c96 100644 --- a/src/codec/xz2/encoder.rs +++ b/src/codec/xz2/encoder.rs @@ -48,11 +48,8 @@ impl Encode for Xz2Encoder { match status { Status::Ok | Status::StreamEnd => Ok(()), - Status::GetCheck => Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected lzma integrity check", - )), - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "out of memory")), + Status::GetCheck => Err(io::Error::other("Unexpected lzma integrity check")), + Status::MemNeeded => Err(io::Error::other("out of memory")), } } @@ -71,11 +68,8 @@ impl Encode for Xz2Encoder { match status { Status::Ok => Ok(false), Status::StreamEnd => Ok(true), - Status::GetCheck => Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected lzma integrity check", - )), - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "out of memory")), + Status::GetCheck => Err(io::Error::other("Unexpected lzma integrity check")), + Status::MemNeeded => Err(io::Error::other("out of memory")), } } @@ -94,11 +88,8 @@ impl Encode for Xz2Encoder { match status { Status::Ok => Ok(false), Status::StreamEnd => Ok(true), - Status::GetCheck => Err(io::Error::new( - io::ErrorKind::Other, - "Unexpected lzma integrity check", - )), - Status::MemNeeded => Err(io::Error::new(io::ErrorKind::Other, "out of memory")), + Status::GetCheck => Err(io::Error::other("Unexpected lzma integrity check")), + Status::MemNeeded => Err(io::Error::other("out of memory")), } } } diff --git a/src/futures/write/generic/decoder.rs b/src/futures/write/generic/decoder.rs index 0a00657..31f6504 100644 --- a/src/futures/write/generic/decoder.rs +++ b/src/futures/write/generic/decoder.rs @@ -88,10 +88,7 @@ impl Decoder { } State::Done => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - "Write after end of stream", - ))) + return Poll::Ready(Err(io::Error::other("Write after end of stream"))) } }; @@ -179,8 +176,7 @@ impl AsyncWrite for Decoder { ready!(self.as_mut().project().writer.as_mut().poll_close(cx))?; Poll::Ready(Ok(())) } else { - Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, + Poll::Ready(Err(io::Error::other( "Attempt to close before finishing input", ))) } diff --git a/src/futures/write/generic/encoder.rs b/src/futures/write/generic/encoder.rs index 84f3bc4..abd18c4 100644 --- a/src/futures/write/generic/encoder.rs +++ b/src/futures/write/generic/encoder.rs @@ -87,10 +87,7 @@ impl Encoder { } State::Finishing | State::Done => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - "Write after close", - ))) + return Poll::Ready(Err(io::Error::other("Write after close"))) } }; @@ -114,10 +111,7 @@ impl Encoder { State::Encoding => this.encoder.flush(&mut output)?, State::Finishing | State::Done => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - "Flush after close", - ))) + return Poll::Ready(Err(io::Error::other("Flush after close"))) } }; diff --git a/src/lib.rs b/src/lib.rs index 310ff62..37b98ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ #![allow(unexpected_cfgs)] #![cfg_attr( feature = "futures-io", - doc = "[`futures-io`](crate::futures) | [`futures::io::AsyncBufRead`](futures_io::AsyncBufRead), [`futures::io::AsyncWrite`](futures_io::AsyncWrite)" + doc = "[`futures-io`] | [`futures::io::AsyncBufRead`](futures_io::AsyncBufRead), [`futures::io::AsyncWrite`](futures_io::AsyncWrite)" )] #![cfg_attr( not(feature = "futures-io"), @@ -40,7 +40,7 @@ )] #![cfg_attr( feature = "tokio", - doc = "[`tokio`](crate::tokio) | [`tokio::io::AsyncBufRead`](::tokio::io::AsyncBufRead), [`tokio::io::AsyncWrite`](::tokio::io::AsyncWrite)" + doc = "[`tokio`] | [`tokio::io::AsyncBufRead`](::tokio::io::AsyncBufRead), [`tokio::io::AsyncWrite`](::tokio::io::AsyncWrite)" )] #![cfg_attr( not(feature = "tokio"), diff --git a/src/tokio/write/generic/decoder.rs b/src/tokio/write/generic/decoder.rs index d03dd30..075c1ec 100644 --- a/src/tokio/write/generic/decoder.rs +++ b/src/tokio/write/generic/decoder.rs @@ -88,10 +88,7 @@ impl Decoder { } State::Done => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - "Write after end of stream", - ))) + return Poll::Ready(Err(io::Error::other("Write after end of stream"))) } }; @@ -179,8 +176,7 @@ impl AsyncWrite for Decoder { ready!(self.as_mut().project().writer.as_mut().poll_shutdown(cx))?; Poll::Ready(Ok(())) } else { - Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, + Poll::Ready(Err(io::Error::other( "Attempt to shutdown before finishing input", ))) } diff --git a/src/tokio/write/generic/encoder.rs b/src/tokio/write/generic/encoder.rs index 5f88ce3..6e39bfb 100644 --- a/src/tokio/write/generic/encoder.rs +++ b/src/tokio/write/generic/encoder.rs @@ -96,10 +96,7 @@ impl Encoder { }, State::Finishing | State::Done => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - "Write after shutdown", - ))) + return Poll::Ready(Err(io::Error::other("Write after shutdown"))) } }; @@ -123,10 +120,7 @@ impl Encoder { State::Encoding | State::Flushing => this.encoder.flush(&mut output)?, State::Finishing | State::Done => { - return Poll::Ready(Err(io::Error::new( - io::ErrorKind::Other, - "Flush after shutdown", - ))) + return Poll::Ready(Err(io::Error::other("Flush after shutdown"))) } }; *this.state = State::Flushing;