From cae7fd50698237e3e981da3110e62c91d06fb16f Mon Sep 17 00:00:00 2001 From: Aron Parker Date: Sat, 23 Apr 2022 10:38:57 +0200 Subject: [PATCH] Simplify io:Error creation A lot of errors were created using io::Error::from(io::ErrorKind::*), which can be replaced with the more concise io::ErrorKind::*.into(). --- src/decode.rs | 6 +++--- src/encode.rs | 2 +- src/lib.rs | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index b8f6d1c..1393d03 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -517,7 +517,7 @@ impl DecompressorReader { } else { Err(IntoInnerError::new( self, - io::Error::from(io::ErrorKind::UnexpectedEof), + io::ErrorKind::UnexpectedEof.into(), )) } } @@ -547,7 +547,7 @@ impl Read for DecompressorReader { _ if bytes_written > 0 => return Ok(bytes_written), DecoderInfo::Finished => return Ok(0), DecoderInfo::NeedsMoreInput if eof => { - return Err(io::Error::from(io::ErrorKind::UnexpectedEof)); + return Err(io::ErrorKind::UnexpectedEof.into()); } DecoderInfo::NeedsMoreInput => continue, DecoderInfo::NeedsMoreOutput if buf.is_empty() => return Ok(0), @@ -654,7 +654,7 @@ impl DecompressorWriter { } else { Err(IntoInnerError::new( self, - io::Error::from(io::ErrorKind::UnexpectedEof), + io::ErrorKind::UnexpectedEof.into(), )) } } diff --git a/src/encode.rs b/src/encode.rs index 2431d10..4ea9969 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -598,7 +598,7 @@ impl CompressorReader { } else { Err(IntoInnerError::new( self, - io::Error::from(io::ErrorKind::UnexpectedEof), + io::ErrorKind::UnexpectedEof.into(), )) } } diff --git a/src/lib.rs b/src/lib.rs index 044f59c..e8cc926 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,7 +127,6 @@ pub use decode::DecompressorReader; pub use decode::DecompressorWriter; use brotlic_sys::*; -use std::io::ErrorKind; use std::os::raw::c_int; use std::{fmt, io}; use std::error::Error; @@ -745,7 +744,7 @@ impl Error for CompressError {} impl From for io::Error { fn from(err: CompressError) -> Self { - io::Error::new(ErrorKind::Other, err) + io::Error::new(io::ErrorKind::Other, err) } } @@ -763,7 +762,7 @@ impl Error for DecompressError {} impl From for io::Error { fn from(err: DecompressError) -> Self { - io::Error::new(ErrorKind::Other, err) + io::Error::new(io::ErrorKind::Other, err) } }