use core::fmt::{self, Display, Formatter};
use core::hint::unreachable_unchecked;
#[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 ErrorKind {
#[inline]
#[must_use]
#[track_caller]
pub(crate) const unsafe fn from_usize_unchecked(value: usize) -> Self {
const ADDR_IN_USE: usize = ErrorKind::AddrInUse as usize;
const ADDR_NOT_AVAILABLE: usize = ErrorKind::AddrNotAvailable as usize;
const ALREADY_EXISTS: usize = ErrorKind::AlreadyExists as usize;
const ARGUMENT_LIST_TOO_LONG: usize = ErrorKind::ArgumentListTooLong as usize;
const BROKEN_PIPE: usize = ErrorKind::BrokenPipe as usize;
const CONNECTION_ABORTED: usize = ErrorKind::ConnectionAborted as usize;
const CONNECTION_REFUSED: usize = ErrorKind::ConnectionRefused as usize;
const CONNECTION_RESET: usize = ErrorKind::ConnectionReset as usize;
const CROSSES_DEVICES: usize = ErrorKind::CrossesDevices as usize;
const DEADLOCK: usize = ErrorKind::Deadlock as usize;
const DIRECTORY_NOT_EMPTY: usize = ErrorKind::DirectoryNotEmpty as usize;
const EXECUTABLE_FILE_BUSY: usize = ErrorKind::ExecutableFileBusy as usize;
const FILE_TOO_LARGE: usize = ErrorKind::FileTooLarge as usize;
const HOST_UNREACHABLE: usize = ErrorKind::HostUnreachable as usize;
const INTERRUPTED: usize = ErrorKind::Interrupted as usize;
const INVALID_DATA: usize = ErrorKind::InvalidData as usize;
const INVALID_FILENAME: usize = ErrorKind::InvalidFilename as usize;
const INVALID_INPUT: usize = ErrorKind::InvalidInput as usize;
const IS_A_DIRECTORY: usize = ErrorKind::IsADirectory as usize;
const NETWORK_DOWN: usize = ErrorKind::NetworkDown as usize;
const NETWORK_UNREACHABLE: usize = ErrorKind::NetworkUnreachable as usize;
const NOT_ADIRECTORY: usize = ErrorKind::NotADirectory as usize;
const NOT_CONNECTED: usize = ErrorKind::NotConnected as usize;
const NOT_FOUND: usize = ErrorKind::NotFound as usize;
const NOT_SEEKABLE: usize = ErrorKind::NotSeekable as usize;
const OUT_OF_MEMORY: usize = ErrorKind::OutOfMemory as usize;
const PERMISSION_DENIED: usize = ErrorKind::PermissionDenied as usize;
const QUOTA_EXCEEDED: usize = ErrorKind::QuotaExceeded as usize;
const READ_ONLY_FILESYSTEM: usize = ErrorKind::ReadOnlyFilesystem as usize;
const RESOURCE_BUSY: usize = ErrorKind::ResourceBusy as usize;
const STALE_NETWORK_FILE_HANDLE: usize = ErrorKind::StaleNetworkFileHandle as usize;
const STORAGE_FULL: usize = ErrorKind::StorageFull as usize;
const TIMED_OUT: usize = ErrorKind::TimedOut as usize;
const TOO_MANY_LINKS: usize = ErrorKind::TooManyLinks as usize;
const UNEXPECTED_EOF: usize = ErrorKind::UnexpectedEof as usize;
const UNSUPPORTED: usize = ErrorKind::Unsupported as usize;
const WOULD_BLOCK: usize = ErrorKind::WouldBlock as usize;
const WRITE_ZERO: usize = ErrorKind::WriteZero as usize;
match value {
ADDR_IN_USE => Self::AddrInUse,
ADDR_NOT_AVAILABLE => Self::AddrNotAvailable,
ALREADY_EXISTS => Self::AlreadyExists,
ARGUMENT_LIST_TOO_LONG => Self::ArgumentListTooLong,
BROKEN_PIPE => Self::BrokenPipe,
CONNECTION_ABORTED => Self::ConnectionAborted,
CONNECTION_REFUSED => Self::ConnectionRefused,
CONNECTION_RESET => Self::ConnectionReset,
CROSSES_DEVICES => Self::CrossesDevices,
DEADLOCK => Self::Deadlock,
DIRECTORY_NOT_EMPTY => Self::DirectoryNotEmpty,
EXECUTABLE_FILE_BUSY => Self::ExecutableFileBusy,
FILE_TOO_LARGE => Self::FileTooLarge,
HOST_UNREACHABLE => Self::HostUnreachable,
INTERRUPTED => Self::Interrupted,
INVALID_DATA => Self::InvalidData,
INVALID_FILENAME => Self::InvalidFilename,
INVALID_INPUT => Self::InvalidInput,
IS_A_DIRECTORY => Self::IsADirectory,
NETWORK_DOWN => Self::NetworkDown,
NETWORK_UNREACHABLE => Self::NetworkUnreachable,
NOT_ADIRECTORY => Self::NotADirectory,
NOT_CONNECTED => Self::NotConnected,
NOT_FOUND => Self::NotFound,
NOT_SEEKABLE => Self::NotSeekable,
OUT_OF_MEMORY => Self::OutOfMemory,
PERMISSION_DENIED => Self::PermissionDenied,
QUOTA_EXCEEDED => Self::QuotaExceeded,
READ_ONLY_FILESYSTEM => Self::ReadOnlyFilesystem,
RESOURCE_BUSY => Self::ResourceBusy,
STALE_NETWORK_FILE_HANDLE => Self::StaleNetworkFileHandle,
STORAGE_FULL => Self::StorageFull,
TIMED_OUT => Self::TimedOut,
TOO_MANY_LINKS => Self::TooManyLinks,
UNEXPECTED_EOF => Self::UnexpectedEof,
UNSUPPORTED => Self::Unsupported,
WOULD_BLOCK => Self::WouldBlock,
WRITE_ZERO => Self::WriteZero,
_ => unsafe { unreachable_unchecked() }
}
}
}
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,
}
}
}