refactor: change invalid_state() return type to io::Result<T>
Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
This commit is contained in:
parent
2e679997b0
commit
7471cf526f
1 changed files with 8 additions and 8 deletions
16
src/read.rs
16
src/read.rs
|
@ -184,11 +184,11 @@ impl<'a> CryptoReader<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
fn invalid_state() -> io::Error {
|
fn invalid_state<T>() -> io::Result<T> {
|
||||||
io::Error::new(
|
Err(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
"ZipFileReader was in an invalid state",
|
"ZipFileReader was in an invalid state",
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum ZipFileReader<'a> {
|
pub(crate) enum ZipFileReader<'a> {
|
||||||
|
@ -200,7 +200,7 @@ pub(crate) enum ZipFileReader<'a> {
|
||||||
impl<'a> Read for ZipFileReader<'a> {
|
impl<'a> Read for ZipFileReader<'a> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
match self {
|
match self {
|
||||||
ZipFileReader::NoReader => Err(invalid_state()),
|
ZipFileReader::NoReader => invalid_state(),
|
||||||
ZipFileReader::Raw(r) => r.read(buf),
|
ZipFileReader::Raw(r) => r.read(buf),
|
||||||
ZipFileReader::Compressed(r) => r.read(buf),
|
ZipFileReader::Compressed(r) => r.read(buf),
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ impl<'a> Read for ZipFileReader<'a> {
|
||||||
|
|
||||||
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
|
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
ZipFileReader::NoReader => Err(invalid_state()),
|
ZipFileReader::NoReader => invalid_state(),
|
||||||
ZipFileReader::Raw(r) => r.read_exact(buf),
|
ZipFileReader::Raw(r) => r.read_exact(buf),
|
||||||
ZipFileReader::Compressed(r) => r.read_exact(buf),
|
ZipFileReader::Compressed(r) => r.read_exact(buf),
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ impl<'a> Read for ZipFileReader<'a> {
|
||||||
|
|
||||||
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
||||||
match self {
|
match self {
|
||||||
ZipFileReader::NoReader => Err(invalid_state()),
|
ZipFileReader::NoReader => invalid_state(),
|
||||||
ZipFileReader::Raw(r) => r.read_to_end(buf),
|
ZipFileReader::Raw(r) => r.read_to_end(buf),
|
||||||
ZipFileReader::Compressed(r) => r.read_to_end(buf),
|
ZipFileReader::Compressed(r) => r.read_to_end(buf),
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ impl<'a> Read for ZipFileReader<'a> {
|
||||||
|
|
||||||
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
|
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
|
||||||
match self {
|
match self {
|
||||||
ZipFileReader::NoReader => Err(invalid_state()),
|
ZipFileReader::NoReader => invalid_state(),
|
||||||
ZipFileReader::Raw(r) => r.read_to_string(buf),
|
ZipFileReader::Raw(r) => r.read_to_string(buf),
|
||||||
ZipFileReader::Compressed(r) => r.read_to_string(buf),
|
ZipFileReader::Compressed(r) => r.read_to_string(buf),
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ impl<'a> Read for ZipFileReader<'a> {
|
||||||
impl<'a> ZipFileReader<'a> {
|
impl<'a> ZipFileReader<'a> {
|
||||||
fn into_inner(self) -> io::Result<io::Take<&'a mut dyn Read>> {
|
fn into_inner(self) -> io::Result<io::Take<&'a mut dyn Read>> {
|
||||||
match self {
|
match self {
|
||||||
ZipFileReader::NoReader => Err(invalid_state()),
|
ZipFileReader::NoReader => invalid_state(),
|
||||||
ZipFileReader::Raw(r) => Ok(r),
|
ZipFileReader::Raw(r) => Ok(r),
|
||||||
ZipFileReader::Compressed(r) => {
|
ZipFileReader::Compressed(r) => {
|
||||||
Ok(r.into_inner().into_inner().into_inner().into_inner())
|
Ok(r.into_inner().into_inner().into_inner().into_inner())
|
||||||
|
|
Loading…
Add table
Reference in a new issue