Skip to main content

ErrorKind

Enum ErrorKind 

Source
#[non_exhaustive]
pub enum ErrorKind {
Show 41 variants NotFound, PermissionDenied, ConnectionRefused, ConnectionReset, HostUnreachable, NetworkUnreachable, ConnectionAborted, NotConnected, AddrInUse, AddrNotAvailable, NetworkDown, BrokenPipe, AlreadyExists, WouldBlock, NotADirectory, IsADirectory, DirectoryNotEmpty, ReadOnlyFilesystem, FilesystemLoop, StaleNetworkFileHandle, InvalidInput, InvalidData, TimedOut, WriteZero, StorageFull, NotSeekable, QuotaExceeded, FileTooLarge, ResourceBusy, ExecutableFileBusy, Deadlock, CrossesDevices, TooManyLinks, InvalidFilename, ArgumentListTooLong, Interrupted, Unsupported, UnexpectedEof, OutOfMemory, InProgress, Other,
}
๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)
Expand description

A list specifying general categories of I/O error.

This list is intended to grow over time and it is not recommended to exhaustively match against it.

ยงHandling errors and matching on ErrorKind

In application code, use match for the ErrorKind values you are expecting; use _ to match โ€œall other errorsโ€.

In comprehensive and thorough tests that want to verify that a test doesnโ€™t return any known incorrect error kind, you may want to cut-and-paste the current full list of errors from here into your test code, and then match _ as the correct case. This seems counterintuitive, but it will make your tests more robust. In particular, if you want to verify that your code does produce an unrecognized error kind, the robust solution is to check for all the recognized error kinds and fail in those cases.

Variants (Non-exhaustive)ยง

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
ยง

NotFound

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

An entity was not found, often a file.

ยง

PermissionDenied

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The operation lacked the necessary privileges to complete.

ยง

ConnectionRefused

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The connection was refused by the remote server.

ยง

ConnectionReset

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The connection was reset by the remote server.

ยง

HostUnreachable

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The remote host is not reachable.

ยง

NetworkUnreachable

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The network containing the remote host is not reachable.

ยง

ConnectionAborted

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The connection was aborted (terminated) by the remote server.

ยง

NotConnected

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The network operation failed because it was not connected yet.

ยง

AddrInUse

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

A socket address could not be bound because the address is already in use elsewhere.

ยง

AddrNotAvailable

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

A nonexistent interface was requested or the requested address was not local.

ยง

NetworkDown

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The systemโ€™s networking is down.

ยง

BrokenPipe

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The operation failed because a pipe was closed.

ยง

AlreadyExists

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

An entity already exists, often a file.

ยง

WouldBlock

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The operation needs to block to complete, but the blocking operation was requested to not occur.

ยง

NotADirectory

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

A filesystem object is, unexpectedly, not a directory.

For example, a filesystem path was specified where one of the intermediate directory components was, in fact, a plain file.

ยง

IsADirectory

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The filesystem object is, unexpectedly, a directory.

A directory was specified when a non-directory was expected.

ยง

DirectoryNotEmpty

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

A non-empty directory was specified where an empty directory was expected.

ยง

ReadOnlyFilesystem

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The filesystem or storage medium is read-only, but a write operation was attempted.

ยง

FilesystemLoop

๐Ÿ”ฌThis is a nightly-only experimental API. (io_error_more #86442)

Loop in the filesystem or IO subsystem; often, too many levels of symbolic links.

There was a loop (or excessively long chain) resolving a filesystem object or file IO object.

On Unix this is usually the result of a symbolic link loop; or, of exceeding the system-specific limit on the depth of symlink traversal.

ยง

StaleNetworkFileHandle

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Stale network file handle.

With some network filesystems, notably NFS, an open file (or directory) can be invalidated by problems with the network or server.

ยง

InvalidInput

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

A parameter was incorrect.

ยง

InvalidData

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Data not valid for the operation were encountered.

Unlike InvalidInput, this typically means that the operation parameters were valid, however the error was caused by malformed input data.

For example, a function that reads a file into a string will error with InvalidData if the fileโ€™s contents are not valid UTF-8.

ยง

TimedOut

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The I/O operationโ€™s timeout expired, causing it to be canceled.

ยง

WriteZero

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

An error returned when an operation could not be completed because a call to an underlying writer returned Ok(0).

This typically means that an operation could only succeed if it wrote a particular number of bytes but only a smaller number of bytes could be written.

ยง

StorageFull

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

The underlying storage (typically, a filesystem) is full.

This does not include out of quota errors.

ยง

NotSeekable

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Seek on unseekable file.

Seeking was attempted on an open file handle which is not suitable for seeking - for example, on Unix, a named pipe opened with File::open.

ยง

QuotaExceeded

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Filesystem quota or some other kind of quota was exceeded.

ยง

FileTooLarge

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

File larger than allowed or supported.

This might arise from a hard limit of the underlying filesystem or file access API, or from an administratively imposed resource limitation. Simple disk full, and out of quota, have their own errors.

ยง

ResourceBusy

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Resource is busy.

ยง

ExecutableFileBusy

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Executable file is busy.

An attempt was made to write to a file which is also in use as a running program. (Not all operating systems detect this situation.)

ยง

Deadlock

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Deadlock (avoided).

A file locking operation would result in deadlock. This situation is typically detected, if at all, on a best-effort basis.

ยง

CrossesDevices

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Cross-device or cross-filesystem (hard) link or rename.

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Too many (hard) links to the same filesystem object.

The filesystem does not support making so many hardlinks to the same file.

ยง

InvalidFilename

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

A filename was invalid.

This error can also occur if a length limit for a name was exceeded.

ยง

ArgumentListTooLong

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

Program argument list too long.

When trying to run an external program, a system or process limit on the size of the arguments would have been exceeded.

ยง

Interrupted

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

This operation was interrupted.

Interrupted operations can typically be retried.

ยง

Unsupported

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

This operation is unsupported on this platform.

This means that the operation can never succeed.

ยง

UnexpectedEof

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

An error returned when an operation could not be completed because an โ€œend of fileโ€ was reached prematurely.

This typically means that an operation could only succeed if it read a particular number of bytes but only a smaller number of bytes could be read.

ยง

OutOfMemory

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

An operation could not be completed, because it failed to allocate enough memory.

ยง

InProgress

๐Ÿ”ฌThis is a nightly-only experimental API. (io_error_inprogress #130840)

The operation was partially successful and needs to be checked later on due to not blocking.

ยง

Other

๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)

A custom error that does not fall under any other I/O error kind.

This can be used to construct your own errors that do not match any ErrorKind.

This ErrorKind is not used by the standard library.

Errors from the standard library that do not fall under any of the I/O error kinds cannot be matched on, and will only match a wildcard (_) pattern. New ErrorKinds might be added in the future for some of those.

Trait Implementationsยง

1.0.0 ยท Sourceยง

impl Clone for ErrorKind

Sourceยง

fn clone(&self) -> ErrorKind

Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยง

fn clone_from(&mut self, source: &Self)
where Self:,

Performs copy-assignment from source. Read more
1.0.0 ยท Sourceยง

impl Debug for ErrorKind

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
1.60.0 ยท Sourceยง

impl Display for ErrorKind

Sourceยง

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Shows a human-readable description of the ErrorKind.

1.0.0 ยท Sourceยง

impl Hash for ErrorKind

Sourceยง

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 ยท Sourceยง

fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
where Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
1.0.0 ยท Sourceยง

impl Ord for ErrorKind

Sourceยง

fn cmp(&self, other: &ErrorKind) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 ยท Sourceยง

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 ยท Sourceยง

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 ยท Sourceยง

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
1.0.0 ยท Sourceยง

impl PartialEq for ErrorKind

Sourceยง

fn eq(&self, other: &ErrorKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
1.0.0 ยท Sourceยง

impl PartialOrd for ErrorKind

Sourceยง

fn partial_cmp(&self, other: &ErrorKind) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 ยท Sourceยง

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 ยท Sourceยง

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 ยท Sourceยง

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 ยท Sourceยง

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
1.0.0 ยท Sourceยง

impl Copy for ErrorKind

1.0.0 ยท Sourceยง

impl Eq for ErrorKind

1.0.0 ยท Sourceยง

impl StructuralPartialEq for ErrorKind

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.