Skip to content

Commit 33eb8f9

Browse files
committed
perf(http): use custom type for ParseEof error instead of string error
1 parent 7f6673c commit 33eb8f9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/http/io.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
7272
match self.read_from_io() {
7373
Ok(0) => {
7474
trace!("parse eof");
75-
return Err(io::Error::new(io::ErrorKind::UnexpectedEof, "parse eof").into());
75+
//TODO: With Rust 1.14, this can be Error::from(ErrorKind)
76+
return Err(io::Error::new(io::ErrorKind::UnexpectedEof, ParseEof).into());
7677
}
7778
Ok(_) => {},
7879
Err(e) => match e.kind() {
@@ -316,6 +317,21 @@ impl WriteBuf {
316317
}
317318
}
318319

320+
#[derive(Debug)]
321+
struct ParseEof;
322+
323+
impl fmt::Display for ParseEof {
324+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
325+
f.write_str("parse eof")
326+
}
327+
}
328+
329+
impl ::std::error::Error for ParseEof {
330+
fn description(&self) -> &str {
331+
"parse eof"
332+
}
333+
}
334+
319335
#[cfg(test)]
320336
use std::io::Read;
321337

0 commit comments

Comments
 (0)