Hide Repr details from io::Error, and rework io::Error::new_const
.
This commit is contained in:
parent
71226d717a
commit
554918e311
49 changed files with 345 additions and 269 deletions
|
@ -282,6 +282,7 @@ pub use self::{
|
|||
|
||||
#[unstable(feature = "read_buf", issue = "78485")]
|
||||
pub use self::readbuf::ReadBuf;
|
||||
pub(crate) use error::const_io_error;
|
||||
|
||||
mod buffered;
|
||||
pub(crate) mod copy;
|
||||
|
@ -337,7 +338,10 @@ where
|
|||
let ret = f(g.buf);
|
||||
if str::from_utf8(&g.buf[g.len..]).is_err() {
|
||||
ret.and_then(|_| {
|
||||
Err(Error::new_const(ErrorKind::InvalidData, &"stream did not contain valid UTF-8"))
|
||||
Err(error::const_io_error!(
|
||||
ErrorKind::InvalidData,
|
||||
"stream did not contain valid UTF-8"
|
||||
))
|
||||
})
|
||||
} else {
|
||||
g.len = g.buf.len();
|
||||
|
@ -454,7 +458,7 @@ pub(crate) fn default_read_exact<R: Read + ?Sized>(this: &mut R, mut buf: &mut [
|
|||
}
|
||||
}
|
||||
if !buf.is_empty() {
|
||||
Err(Error::new_const(ErrorKind::UnexpectedEof, &"failed to fill whole buffer"))
|
||||
Err(error::const_io_error!(ErrorKind::UnexpectedEof, "failed to fill whole buffer"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1512,9 +1516,9 @@ pub trait Write {
|
|||
while !buf.is_empty() {
|
||||
match self.write(buf) {
|
||||
Ok(0) => {
|
||||
return Err(Error::new_const(
|
||||
return Err(error::const_io_error!(
|
||||
ErrorKind::WriteZero,
|
||||
&"failed to write whole buffer",
|
||||
"failed to write whole buffer",
|
||||
));
|
||||
}
|
||||
Ok(n) => buf = &buf[n..],
|
||||
|
@ -1580,9 +1584,9 @@ pub trait Write {
|
|||
while !bufs.is_empty() {
|
||||
match self.write_vectored(bufs) {
|
||||
Ok(0) => {
|
||||
return Err(Error::new_const(
|
||||
return Err(error::const_io_error!(
|
||||
ErrorKind::WriteZero,
|
||||
&"failed to write whole buffer",
|
||||
"failed to write whole buffer",
|
||||
));
|
||||
}
|
||||
Ok(n) => IoSlice::advance_slices(&mut bufs, n),
|
||||
|
@ -1657,7 +1661,7 @@ pub trait Write {
|
|||
if output.error.is_err() {
|
||||
output.error
|
||||
} else {
|
||||
Err(Error::new_const(ErrorKind::Uncategorized, &"formatter error"))
|
||||
Err(error::const_io_error!(ErrorKind::Uncategorized, "formatter error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue