impl From<ConnectError> for io::Error

This commit is contained in:
Benjamin Saunders
2021-11-27 14:56:05 -08:00
parent 4b0daad5ce
commit bf2e4016ae
+14 -1
View File
@@ -1,7 +1,7 @@
use std::{
collections::{HashMap, VecDeque},
convert::TryFrom,
fmt, iter,
fmt, io, iter,
net::{IpAddr, SocketAddr},
ops::{Index, IndexMut},
sync::Arc,
@@ -844,6 +844,19 @@ pub enum ConnectError {
UnsupportedVersion,
}
// For compatibility with API consumers
impl From<ConnectError> for io::Error {
fn from(x: ConnectError) -> io::Error {
use ConnectError::*;
let kind = match x {
InvalidDnsName(_) | InvalidRemoteAddress(_) => io::ErrorKind::InvalidData,
EndpointStopping | TooManyConnections | NoDefaultClientConfig => io::ErrorKind::Other,
UnsupportedVersion => io::ErrorKind::InvalidInput,
};
io::Error::new(kind, x)
}
}
/// Reset Tokens which are associated with peer socket addresses
///
/// The standard `HashMap` is used since both `SocketAddr` and `ResetToken` are