+#[repr(C)]
+#[allow(missing_docs)] // If there's no docs upstream, that's good enough for us
+#[derive(Clone, Copy, PartialEq)]
+/// Represents an IO Error. Note that some information is lost in the conversion from Rust.
+pub enum IOError {
+ NotFound,
+ PermissionDenied,
+ ConnectionRefused,
+ ConnectionReset,
+ ConnectionAborted,
+ NotConnected,
+ AddrInUse,
+ AddrNotAvailable,
+ BrokenPipe,
+ AlreadyExists,
+ WouldBlock,
+ InvalidInput,
+ InvalidData,
+ TimedOut,
+ WriteZero,
+ Interrupted,
+ Other,
+ UnexpectedEof,
+}
+#[cfg(feature = "std")]
+impl IOError {
+ pub(crate) fn from_rust(err: std::io::Error) -> Self {
+ match err.kind() {
+ std::io::ErrorKind::NotFound => IOError::NotFound,
+ std::io::ErrorKind::PermissionDenied => IOError::PermissionDenied,
+ std::io::ErrorKind::ConnectionRefused => IOError::ConnectionRefused,
+ std::io::ErrorKind::ConnectionReset => IOError::ConnectionReset,
+ std::io::ErrorKind::ConnectionAborted => IOError::ConnectionAborted,
+ std::io::ErrorKind::NotConnected => IOError::NotConnected,
+ std::io::ErrorKind::AddrInUse => IOError::AddrInUse,
+ std::io::ErrorKind::AddrNotAvailable => IOError::AddrNotAvailable,
+ std::io::ErrorKind::BrokenPipe => IOError::BrokenPipe,
+ std::io::ErrorKind::AlreadyExists => IOError::AlreadyExists,
+ std::io::ErrorKind::WouldBlock => IOError::WouldBlock,
+ std::io::ErrorKind::InvalidInput => IOError::InvalidInput,
+ std::io::ErrorKind::InvalidData => IOError::InvalidData,
+ std::io::ErrorKind::TimedOut => IOError::TimedOut,
+ std::io::ErrorKind::WriteZero => IOError::WriteZero,
+ std::io::ErrorKind::Interrupted => IOError::Interrupted,
+ std::io::ErrorKind::Other => IOError::Other,
+ std::io::ErrorKind::UnexpectedEof => IOError::UnexpectedEof,
+ _ => IOError::Other,
+ }
+ }
+ pub(crate) fn to_rust(&self) -> std::io::Error {
+ std::io::Error::new(match self {
+ IOError::NotFound => std::io::ErrorKind::NotFound,
+ IOError::PermissionDenied => std::io::ErrorKind::PermissionDenied,
+ IOError::ConnectionRefused => std::io::ErrorKind::ConnectionRefused,
+ IOError::ConnectionReset => std::io::ErrorKind::ConnectionReset,
+ IOError::ConnectionAborted => std::io::ErrorKind::ConnectionAborted,
+ IOError::NotConnected => std::io::ErrorKind::NotConnected,
+ IOError::AddrInUse => std::io::ErrorKind::AddrInUse,
+ IOError::AddrNotAvailable => std::io::ErrorKind::AddrNotAvailable,
+ IOError::BrokenPipe => std::io::ErrorKind::BrokenPipe,
+ IOError::AlreadyExists => std::io::ErrorKind::AlreadyExists,
+ IOError::WouldBlock => std::io::ErrorKind::WouldBlock,
+ IOError::InvalidInput => std::io::ErrorKind::InvalidInput,
+ IOError::InvalidData => std::io::ErrorKind::InvalidData,
+ IOError::TimedOut => std::io::ErrorKind::TimedOut,
+ IOError::WriteZero => std::io::ErrorKind::WriteZero,
+ IOError::Interrupted => std::io::ErrorKind::Interrupted,
+ IOError::Other => std::io::ErrorKind::Other,
+ IOError::UnexpectedEof => std::io::ErrorKind::UnexpectedEof,
+ }, "")
+ }
+}
+