Remove public Error constructor from io::Error (#420)
This commit is contained in:
@@ -1136,7 +1136,7 @@ where
|
||||
log::debug!("binding client connection");
|
||||
|
||||
let msg: &'static [u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
|
||||
io.write_all(msg).await?;
|
||||
io.write_all(msg).await.map_err(crate::Error::from_io)?;
|
||||
|
||||
log::debug!("client connection bound");
|
||||
|
||||
|
||||
16
src/error.rs
16
src/error.rs
@@ -73,6 +73,12 @@ impl Error {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_io(err: io::Error) -> Self {
|
||||
Error {
|
||||
kind: Kind::Io(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<proto::Error> for Error {
|
||||
@@ -88,14 +94,6 @@ impl From<proto::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(src: io::Error) -> Error {
|
||||
Error {
|
||||
kind: Kind::Io(src),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reason> for Error {
|
||||
fn from(src: Reason) -> Error {
|
||||
Error {
|
||||
@@ -109,7 +107,7 @@ impl From<SendError> for Error {
|
||||
match src {
|
||||
SendError::User(e) => e.into(),
|
||||
SendError::Connection(reason) => reason.into(),
|
||||
SendError::Io(e) => e.into(),
|
||||
SendError::Io(e) => Error::from_io(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1121,7 +1121,7 @@ where
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
// Flush the codec
|
||||
ready!(self.codec.as_mut().unwrap().flush(cx))?;
|
||||
ready!(self.codec.as_mut().unwrap().flush(cx)).map_err(crate::Error::from_io)?;
|
||||
|
||||
// Return the codec
|
||||
Poll::Ready(Ok(self.codec.take().unwrap()))
|
||||
@@ -1153,13 +1153,13 @@ where
|
||||
let mut rem = PREFACE.len() - self.pos;
|
||||
|
||||
while rem > 0 {
|
||||
let n = ready!(Pin::new(self.inner_mut()).poll_read(cx, &mut buf[..rem]))?;
|
||||
let n = ready!(Pin::new(self.inner_mut()).poll_read(cx, &mut buf[..rem]))
|
||||
.map_err(crate::Error::from_io)?;
|
||||
if n == 0 {
|
||||
return Poll::Ready(Err(io::Error::new(
|
||||
io::ErrorKind::ConnectionReset,
|
||||
"connection closed unexpectedly",
|
||||
)
|
||||
.into()));
|
||||
return Poll::Ready(Err(crate::Error::from_io(io::Error::new(
|
||||
io::ErrorKind::UnexpectedEof,
|
||||
"connection closed before reading preface",
|
||||
))));
|
||||
}
|
||||
|
||||
if PREFACE[self.pos..self.pos + n] != buf[..n] {
|
||||
|
||||
Reference in New Issue
Block a user