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

NotFound

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

An entity was not found, often a file.

ยง

PermissionDenied

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

The operation lacked the necessary privileges to complete.

ยง

ConnectionRefused

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

The connection was refused by the remote server.

ยง

ConnectionReset

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

The connection was reset by the remote server.

ยง

HostUnreachable

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

The remote host is not reachable.

ยง

NetworkUnreachable

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

The network containing the remote host is not reachable.

ยง

ConnectionAborted

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

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

ยง

NotConnected

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

The network operation failed because it was not connected yet.

ยง

AddrInUse

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

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)

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

ยง

NetworkDown

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

The systemโ€™s networking is down.

ยง

BrokenPipe

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

The operation failed because a pipe was closed.

ยง

AlreadyExists

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

An entity already exists, often a file.

ยง

WouldBlock

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

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)

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)

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)

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

ยง

ReadOnlyFilesystem

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

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)

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)

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)

A parameter was incorrect.

ยง

InvalidData

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

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)

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

ยง

WriteZero

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

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.

ยง

StorageFull

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

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)

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)

Filesystem quota or some other kind of quota was exceeded.

ยง

FileTooLarge

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

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)

Resource is busy.

ยง

ExecutableFileBusy

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

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)

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)

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

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

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)

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)

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)

This operation was interrupted.

Interrupted operations can typically be retried.

ยง

Unsupported

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

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)

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)

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

ยง

InProgress

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

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)

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 (const: unstable) ยท 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<(), Error>

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<(), Error>

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 core::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>(&self, state: &mut __H)
where __H: Hasher,

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 (const: unstable) ยท Sourceยง

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) ยท Sourceยง

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท 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)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Sourceยง

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Sourceยง

impl<T> DebugExt<T> for T
where T: Debug,

Sourceยง

impl<T> Downcast for T
where T: Any,

Sourceยง

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Anyโ€™s vtable from &Traitโ€™s.
Sourceยง

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Anyโ€™s vtable from &mut Traitโ€™s.
Sourceยง

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Sourceยง

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> โ“˜

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

impl<A> DynCastExt for A

Sourceยง

fn dyn_cast<T>( self, ) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source>
where A: DynCastExtHelper<T>, T: ?Sized,

Use this to cast from one trait object type to another. Read more
Sourceยง

fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target
where A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>, T: ?Sized,

Use this to upcast a trait to one of its supertraits. Read more
Sourceยง

fn dyn_cast_adv<F, T>( self, ) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source>
where A: DynCastExtAdvHelper<F, T>, F: ?Sized, T: ?Sized,

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the โ€œsourceโ€ trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more
Sourceยง

fn dyn_cast_with_config<C>( self, ) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source>

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
Sourceยง

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Sourceยง

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Sourceยง

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Sourceยง

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Sourceยง

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Sourceยง

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self> โ“˜

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self> โ“˜

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self> โ“˜

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ“˜
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

impl<T> OrdExt<T> for T
where T: Ord + Clone,

Sourceยง

fn update_max(&mut self, new: &T)

Sourceยง

impl<T> Pointable for T

Sourceยง

const ALIGN: usize

The alignment of pointer.
Sourceยง

type Init = T

The type for initializers.
Sourceยง

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Sourceยง

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Sourceยง

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Sourceยง

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
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.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> โ“˜
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self> โ“˜

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

impl<T> RuleType for T
where T: Copy + Debug + Eq + Hash + Ord,