From c915b236aee526ea43dfda0b9689842367ec7636 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 22 Nov 2020 12:56:58 -0800 Subject: [PATCH] Fix is_connection_closed. (#238) Fixes #237. --- src/error.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 86ffdff..5739c43 100644 --- a/src/error.rs +++ b/src/error.rs @@ -83,7 +83,7 @@ impl Error { Some(e) => e, None => return false, }; - let ioe: &Box = match source.downcast_ref() { + let ioe: &io::Error = match source.downcast_ref() { Some(e) => e, None => return false, }; @@ -183,6 +183,17 @@ fn io_error() { assert_eq!(err.to_string(), "http://example.com/: Io: oops: too slow"); } +#[test] +fn connection_closed() { + let ioe = io::Error::new(io::ErrorKind::ConnectionReset, "connection reset"); + let err = ErrorKind::Io.new().src(ioe); + assert!(err.connection_closed()); + + let ioe = io::Error::new(io::ErrorKind::ConnectionAborted, "connection aborted"); + let err = ErrorKind::Io.new().src(ioe); + assert!(err.connection_closed()); +} + #[test] fn error_is_send_and_sync() { fn takes_send(_: impl Send) {}