perf(http): use custom type for ParseEof error instead of string error

This commit is contained in:
Sean McArthur
2017-05-12 16:54:24 -07:00
parent 7f6673c4cd
commit 33eb8f95a3

View File

@@ -72,7 +72,8 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
match self.read_from_io() {
Ok(0) => {
trace!("parse eof");
return Err(io::Error::new(io::ErrorKind::UnexpectedEof, "parse eof").into());
//TODO: With Rust 1.14, this can be Error::from(ErrorKind)
return Err(io::Error::new(io::ErrorKind::UnexpectedEof, ParseEof).into());
}
Ok(_) => {},
Err(e) => match e.kind() {
@@ -316,6 +317,21 @@ impl WriteBuf {
}
}
#[derive(Debug)]
struct ParseEof;
impl fmt::Display for ParseEof {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("parse eof")
}
}
impl ::std::error::Error for ParseEof {
fn description(&self) -> &str {
"parse eof"
}
}
#[cfg(test)]
use std::io::Read;