ErrorKind in std::io - Rust
Description: A list specifying general categories of I/O error.

## ErrorKind

# Enum ErrorKind

1.0.0 · 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,
    }

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.

It is used with the `io::Error` type.

## §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.
§1.0.0

### NotFound

An entity was not found, often a file.

§1.0.0

### PermissionDenied

The operation lacked the necessary privileges to complete.

§1.0.0

### ConnectionRefused

The connection was refused by the remote server.

§1.0.0

### ConnectionReset

The connection was reset by the remote server.

§1.83.0

### HostUnreachable

The remote host is not reachable.

§1.83.0

### NetworkUnreachable

The network containing the remote host is not reachable.

§1.0.0

### ConnectionAborted

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

§1.0.0

### NotConnected

The network operation failed because it was not connected yet.

§1.0.0

### AddrInUse

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

§1.0.0

### AddrNotAvailable

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

§1.83.0

### NetworkDown

The system’s networking is down.

§1.0.0

### BrokenPipe

The operation failed because a pipe was closed.

§1.0.0

### AlreadyExists

An entity already exists, often a file.

§1.0.0

### WouldBlock

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

§1.83.0

### NotADirectory

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.

§1.83.0

### IsADirectory

The filesystem object is, unexpectedly, a directory.

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

§1.83.0

### DirectoryNotEmpty

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

§1.83.0

### ReadOnlyFilesystem

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.

§1.83.0

### StaleNetworkFileHandle

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.

§1.0.0

### InvalidInput

A parameter was incorrect.

§1.2.0

### InvalidData

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.

§1.0.0

### TimedOut

The I/O operation’s timeout expired, causing it to be canceled.

§1.0.0

### WriteZero

An error returned when an operation could not be completed because a call to `write` 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.

§1.83.0

### StorageFull

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

This does not include out of quota errors.

§1.83.0

### NotSeekable

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`.

§1.85.0

### QuotaExceeded

Filesystem quota or some other kind of quota was exceeded.

§1.83.0

### FileTooLarge

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.

§1.83.0

### ResourceBusy

Resource is busy.

§1.83.0

### ExecutableFileBusy

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.)

§1.83.0

### Deadlock

Deadlock (avoided).

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

§1.85.0

### CrossesDevices

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

§1.83.0

### TooManyLinks

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

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

§1.87.0

### InvalidFilename

A filename was invalid.

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

§1.83.0

### ArgumentListTooLong

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.

§1.0.0

### Interrupted

This operation was interrupted.

Interrupted operations can typically be retried.

§1.53.0

### Unsupported

This operation is unsupported on this platform.

This means that the operation can never succeed.

§1.6.0

### UnexpectedEof

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.

§1.54.0

### OutOfMemory

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.

§1.0.0

### Other

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

This can be used to construct your own `Error`s 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 `match`ed on, and will only match a wildcard (`_`) pattern. New `ErrorKind`s 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)

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`.

This is similar to `impl Display for Error`, but doesn’t require first converting to Error.

##### §Examples

    use std::io::ErrorKind;
    assert_eq!("entity not found", ErrorKind::NotFound.to_string());

1.14.0 · Source§

### impl From<ErrorKind> for Error

Intended for use for errors not exposed to the user, where allocating onto the heap (for normal construction via Error::new) is too costly.

Source§

#### fn from(kind: ErrorKind) -> Error

Converts an `ErrorKind` into an `Error`.

This conversion creates a new error with a simple representation of error kind.

##### §Examples

    use std::io::{Error, ErrorKind};

    let not_found = ErrorKind::NotFound;
    let error = Error::from(not_found);
    assert_eq!("entity not found", format!("{error}"));

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>(data: &[Self], state: &mut H)
where H: Hasher, 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§

§

### impl Freeze for ErrorKind

§

### impl RefUnwindSafe for ErrorKind

§

### impl Send for ErrorKind

§

### impl Sync for ErrorKind

§

### impl Unpin for ErrorKind

§

### impl UnwindSafe for ErrorKind

## 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> ToOwned for T
where T: Clone,

Source§

#### type Owned = T

The resulting type after obtaining ownership.
Source§

#### fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

#### fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

### impl<T> ToString for T
where T: Display + ?Sized,

Source§

#### fn to_string(&self) -> String

Converts the given value to a `String`. Read more
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.