use std::io::ErrorKind;
use recoverable::RecoveryInfo;
#[must_use]
pub(crate) fn detect_io_recovery(kind: ErrorKind) -> RecoveryInfo {
match kind {
ErrorKind::WouldBlock
| ErrorKind::TimedOut
| ErrorKind::ConnectionReset
| ErrorKind::ConnectionAborted
| ErrorKind::NotConnected
| ErrorKind::ConnectionRefused
| ErrorKind::AddrInUse
| ErrorKind::AddrNotAvailable
| ErrorKind::BrokenPipe
| ErrorKind::Interrupted => RecoveryInfo::retry(),
_ => RecoveryInfo::never(),
}
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use super::*;
#[test]
fn detect_io_recovery_never() {
assert_eq!(detect_io_recovery(ErrorKind::NotFound), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::PermissionDenied), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::AlreadyExists), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::InvalidData), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::InvalidInput), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::UnexpectedEof), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::WriteZero), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::Unsupported), RecoveryInfo::never());
assert_eq!(detect_io_recovery(ErrorKind::OutOfMemory), RecoveryInfo::never());
}
#[test]
fn detect_io_recovery_retry() {
assert_eq!(detect_io_recovery(ErrorKind::WouldBlock), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::TimedOut), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::ConnectionReset), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::ConnectionAborted), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::NotConnected), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::ConnectionRefused), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::AddrInUse), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::AddrNotAvailable), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::BrokenPipe), RecoveryInfo::retry());
assert_eq!(detect_io_recovery(ErrorKind::Interrupted), RecoveryInfo::retry());
}
}