use core::fmt::{self, Display, Formatter};
#[non_exhaustive]
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd
)]
pub enum ErrorKind {
AddrInUse,
AddrNotAvailable,
AlreadyExists,
ArgumentListTooLong,
BrokenPipe,
ConnectionAborted,
ConnectionRefused,
ConnectionReset,
CrossesDevices,
Deadlock,
DirectoryNotEmpty,
ExecutableFileBusy,
FileTooLarge,
HostUnreachable,
Interrupted,
InvalidData,
InvalidFilename,
InvalidInput,
IsADirectory,
NetworkDown,
NetworkUnreachable,
NotADirectory,
NotConnected,
NotFound,
NotSeekable,
Other,
OutOfMemory,
PermissionDenied,
QuotaExceeded,
ReadOnlyFilesystem,
ResourceBusy,
StaleNetworkFileHandle,
StorageFull,
TimedOut,
TooManyLinks,
UnexpectedEof,
Unsupported,
WouldBlock,
WriteZero,
}
impl Display for ErrorKind {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self {
Self::AddrInUse => {
write!(f, "address is already in use")
}
Self::AddrNotAvailable => {
write!(f, "address is not available")
}
Self::AlreadyExists => {
write!(f, "path already exists")
}
Self::ArgumentListTooLong => {
write!(f, "argument list is too long")
}
Self::BrokenPipe => {
write!(f, "pipe is broken")
}
Self::ConnectionAborted => {
write!(f, "connection has been aborted")
}
Self::ConnectionRefused => {
write!(f, "connection has been refused")
}
Self::ConnectionReset => {
write!(f, "connection has been reset")
}
Self::CrossesDevices => {
write!(f, "cross-device link")
}
Self::Deadlock => {
write!(f, "deadlock")
}
Self::DirectoryNotEmpty => {
write!(f, "directory is not empty")
}
Self::ExecutableFileBusy => {
write!(f, "executable file is busy")
}
Self::FileTooLarge => {
write!(f, "file is too large")
}
Self::HostUnreachable => {
write!(f, "host is unreachable")
}
Self::Interrupted => {
write!(f, "operation was interrupted")
}
Self::InvalidData => {
write!(f, "invalid data")
}
Self::InvalidFilename => {
write!(f, "invalid file name")
}
Self::InvalidInput => {
write!(f, "invalid input")
}
Self::IsADirectory => {
write!(f, "path is a directory")
}
Self::NetworkDown => {
write!(f, "network is down")
}
Self::NetworkUnreachable => {
write!(f, "network is unreachable")
}
Self::NotADirectory => {
write!(f, "path is not a directory")
}
Self::NotConnected => {
write!(f, "connection is missing")
}
Self::NotFound => {
write!(f, "path was not found")
}
Self::NotSeekable => {
write!(f, "file is unseekable")
}
Self::Other => {
write!(f, "unknown error")
}
Self::OutOfMemory => {
write!(f, "out of memory")
}
Self::PermissionDenied => {
write!(f, "permission was denied")
}
Self::QuotaExceeded => {
write!(f, "quota has been exceeded")
}
Self::ReadOnlyFilesystem => {
write!(f, "file system is read-only")
}
Self::ResourceBusy => {
write!(f, "resource is busy")
}
Self::StaleNetworkFileHandle=> {
write!(f, "network file handle is stale")
}
Self::StorageFull => {
write!(f, "storage is full")
}
Self::TimedOut => {
write!(f, "time out")
}
Self::TooManyLinks => {
write!(f, "too many links")
}
Self::UnexpectedEof => {
write!(f, "unexpected end of file")
}
Self::Unsupported => {
write!(f, "unsupported operation")
}
Self::WouldBlock => {
write!(f, "operation would block")
}
Self::WriteZero => {
write!(f, "zero write")
}
}
}
}
#[cfg(feature = "std")]
impl From<std::io::ErrorKind> for ErrorKind {
#[inline]
fn from(value: std::io::ErrorKind) -> Self {
match value {
std::io::ErrorKind::AddrInUse => Self::AddrInUse,
std::io::ErrorKind::AddrNotAvailable => Self::AddrNotAvailable,
std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
std::io::ErrorKind::ArgumentListTooLong => Self::ArgumentListTooLong,
std::io::ErrorKind::BrokenPipe => Self::BrokenPipe,
std::io::ErrorKind::ConnectionAborted => Self::ConnectionAborted,
std::io::ErrorKind::ConnectionRefused => Self::ConnectionRefused,
std::io::ErrorKind::ConnectionReset => Self::ConnectionReset,
std::io::ErrorKind::CrossesDevices => Self::CrossesDevices,
std::io::ErrorKind::Deadlock => Self::Deadlock,
std::io::ErrorKind::DirectoryNotEmpty => Self::DirectoryNotEmpty,
std::io::ErrorKind::ExecutableFileBusy => Self::ExecutableFileBusy,
std::io::ErrorKind::FileTooLarge => Self::FileTooLarge,
std::io::ErrorKind::HostUnreachable => Self::HostUnreachable,
std::io::ErrorKind::Interrupted => Self::Interrupted,
std::io::ErrorKind::InvalidData => Self::InvalidData,
std::io::ErrorKind::InvalidFilename => Self::InvalidFilename,
std::io::ErrorKind::InvalidInput => Self::InvalidInput,
std::io::ErrorKind::IsADirectory => Self::IsADirectory,
std::io::ErrorKind::NetworkDown => Self::NetworkDown,
std::io::ErrorKind::NetworkUnreachable => Self::NetworkUnreachable,
std::io::ErrorKind::NotADirectory => Self::NotADirectory,
std::io::ErrorKind::NotConnected => Self::NotConnected,
std::io::ErrorKind::NotFound => Self::NotFound,
std::io::ErrorKind::NotSeekable => Self::NotSeekable,
std::io::ErrorKind::OutOfMemory => Self::OutOfMemory,
std::io::ErrorKind::PermissionDenied => Self::PermissionDenied,
std::io::ErrorKind::QuotaExceeded => Self::QuotaExceeded,
std::io::ErrorKind::ReadOnlyFilesystem => Self::ReadOnlyFilesystem,
std::io::ErrorKind::ResourceBusy => Self::ResourceBusy,
std::io::ErrorKind::StaleNetworkFileHandle => Self::StaleNetworkFileHandle,
std::io::ErrorKind::StorageFull => Self::StorageFull,
std::io::ErrorKind::TimedOut => Self::TimedOut,
std::io::ErrorKind::TooManyLinks => Self::TooManyLinks,
std::io::ErrorKind::UnexpectedEof => Self::UnexpectedEof,
std::io::ErrorKind::Unsupported => Self::Unsupported,
std::io::ErrorKind::WouldBlock => Self::WouldBlock,
std::io::ErrorKind::WriteZero => Self::WriteZero,
| std::io::ErrorKind::Other
| _
=> Self::Other,
}
}
}
#[cfg(feature = "std")]
impl From<ErrorKind> for std::io::ErrorKind {
#[inline]
fn from(value: ErrorKind) -> Self {
match value {
ErrorKind::AddrInUse => Self::AddrInUse,
ErrorKind::AddrNotAvailable => Self::AddrNotAvailable,
ErrorKind::AlreadyExists => Self::AlreadyExists,
ErrorKind::ArgumentListTooLong => Self::ArgumentListTooLong,
ErrorKind::BrokenPipe => Self::BrokenPipe,
ErrorKind::ConnectionAborted => Self::ConnectionAborted,
ErrorKind::ConnectionRefused => Self::ConnectionRefused,
ErrorKind::ConnectionReset => Self::ConnectionReset,
ErrorKind::CrossesDevices => Self::CrossesDevices,
ErrorKind::Deadlock => Self::Deadlock,
ErrorKind::DirectoryNotEmpty => Self::DirectoryNotEmpty,
ErrorKind::ExecutableFileBusy => Self::ExecutableFileBusy,
ErrorKind::FileTooLarge => Self::FileTooLarge,
ErrorKind::HostUnreachable => Self::HostUnreachable,
ErrorKind::Interrupted => Self::Interrupted,
ErrorKind::InvalidData => Self::InvalidData,
ErrorKind::InvalidFilename => Self::InvalidFilename,
ErrorKind::InvalidInput => Self::InvalidInput,
ErrorKind::IsADirectory => Self::IsADirectory,
ErrorKind::NetworkDown => Self::NetworkDown,
ErrorKind::NetworkUnreachable => Self::NetworkUnreachable,
ErrorKind::NotADirectory => Self::NotADirectory,
ErrorKind::NotConnected => Self::NotConnected,
ErrorKind::NotFound => Self::NotFound,
ErrorKind::NotSeekable => Self::NotSeekable,
ErrorKind::Other => Self::Other,
ErrorKind::OutOfMemory => Self::OutOfMemory,
ErrorKind::PermissionDenied => Self::PermissionDenied,
ErrorKind::QuotaExceeded => Self::QuotaExceeded,
ErrorKind::ReadOnlyFilesystem => Self::ReadOnlyFilesystem,
ErrorKind::ResourceBusy => Self::ResourceBusy,
ErrorKind::StaleNetworkFileHandle => Self::StaleNetworkFileHandle,
ErrorKind::StorageFull => Self::StorageFull,
ErrorKind::TimedOut => Self::TimedOut,
ErrorKind::TooManyLinks => Self::TooManyLinks,
ErrorKind::UnexpectedEof => Self::UnexpectedEof,
ErrorKind::Unsupported => Self::Unsupported,
ErrorKind::WouldBlock => Self::WouldBlock,
ErrorKind::WriteZero => Self::WriteZero,
}
}
}