1#![unstable(feature = "core_io", issue = "154046")]
23use crate::fmt;
45/// The type of raw OS error codes.
6///
7/// This is an [`i32`] on all currently supported platforms, but platforms
8/// added in the future (such as UEFI) may use a different primitive type like
9/// [`usize`]. Use `as` or [`into`] conversions where applicable to ensure maximum
10/// portability.
11///
12/// [`into`]: Into::into
13#[unstable(feature = "raw_os_error_ty", issue = "107792")]
14pub type RawOsError = cfg_select! {
15 target_os = "uefi" => usize,
16_ => i32,
17};
1819/// A list specifying general categories of I/O error.
20///
21/// This list is intended to grow over time and it is not recommended to
22/// exhaustively match against it.
23///
24/// It is used with the [`io::Error`][error] type.
25///
26/// [error]: ../../std/io/struct.Error.html
27///
28/// # Handling errors and matching on `ErrorKind`
29///
30/// In application code, use `match` for the `ErrorKind` values you are
31/// expecting; use `_` to match "all other errors".
32///
33/// In comprehensive and thorough tests that want to verify that a test doesn't
34/// return any known incorrect error kind, you may want to cut-and-paste the
35/// current full list of errors from here into your test code, and then match
36/// `_` as the correct case. This seems counterintuitive, but it will make your
37/// tests more robust. In particular, if you want to verify that your code does
38/// produce an unrecognized error kind, the robust solution is to check for all
39/// the recognized error kinds and fail in those cases.
40#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::clone::Clone for ErrorKind {
#[inline]
fn clone(&self) -> ErrorKind { *self }
}Clone, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::marker::Copy for ErrorKind { }Copy, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::fmt::Debug for ErrorKind {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::write_str(f,
match self {
ErrorKind::NotFound => "NotFound",
ErrorKind::PermissionDenied => "PermissionDenied",
ErrorKind::ConnectionRefused => "ConnectionRefused",
ErrorKind::ConnectionReset => "ConnectionReset",
ErrorKind::HostUnreachable => "HostUnreachable",
ErrorKind::NetworkUnreachable => "NetworkUnreachable",
ErrorKind::ConnectionAborted => "ConnectionAborted",
ErrorKind::NotConnected => "NotConnected",
ErrorKind::AddrInUse => "AddrInUse",
ErrorKind::AddrNotAvailable => "AddrNotAvailable",
ErrorKind::NetworkDown => "NetworkDown",
ErrorKind::BrokenPipe => "BrokenPipe",
ErrorKind::AlreadyExists => "AlreadyExists",
ErrorKind::WouldBlock => "WouldBlock",
ErrorKind::NotADirectory => "NotADirectory",
ErrorKind::IsADirectory => "IsADirectory",
ErrorKind::DirectoryNotEmpty => "DirectoryNotEmpty",
ErrorKind::ReadOnlyFilesystem => "ReadOnlyFilesystem",
ErrorKind::FilesystemLoop => "FilesystemLoop",
ErrorKind::StaleNetworkFileHandle => "StaleNetworkFileHandle",
ErrorKind::InvalidInput => "InvalidInput",
ErrorKind::InvalidData => "InvalidData",
ErrorKind::TimedOut => "TimedOut",
ErrorKind::WriteZero => "WriteZero",
ErrorKind::StorageFull => "StorageFull",
ErrorKind::NotSeekable => "NotSeekable",
ErrorKind::QuotaExceeded => "QuotaExceeded",
ErrorKind::FileTooLarge => "FileTooLarge",
ErrorKind::ResourceBusy => "ResourceBusy",
ErrorKind::ExecutableFileBusy => "ExecutableFileBusy",
ErrorKind::Deadlock => "Deadlock",
ErrorKind::CrossesDevices => "CrossesDevices",
ErrorKind::TooManyLinks => "TooManyLinks",
ErrorKind::InvalidFilename => "InvalidFilename",
ErrorKind::ArgumentListTooLong => "ArgumentListTooLong",
ErrorKind::Interrupted => "Interrupted",
ErrorKind::Unsupported => "Unsupported",
ErrorKind::UnexpectedEof => "UnexpectedEof",
ErrorKind::OutOfMemory => "OutOfMemory",
ErrorKind::InProgress => "InProgress",
ErrorKind::Other => "Other",
ErrorKind::Uncategorized => "Uncategorized",
})
}
}Debug, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::cmp::Eq for ErrorKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::hash::Hash for ErrorKind {
#[inline]
fn hash<__H: crate::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = crate::intrinsics::discriminant_value(self);
crate::hash::Hash::hash(&__self_discr, state)
}
}Hash, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::cmp::Ord for ErrorKind {
#[inline]
fn cmp(&self, other: &ErrorKind) -> crate::cmp::Ordering {
let __self_discr = crate::intrinsics::discriminant_value(self);
let __arg1_discr = crate::intrinsics::discriminant_value(other);
crate::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
}
}Ord, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::cmp::PartialEq for ErrorKind {
#[inline]
fn eq(&self, other: &ErrorKind) -> bool {
let __self_discr = crate::intrinsics::discriminant_value(self);
let __arg1_discr = crate::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl crate::cmp::PartialOrd for ErrorKind {
#[inline]
fn partial_cmp(&self, other: &ErrorKind)
-> crate::option::Option<crate::cmp::Ordering> {
crate::option::Option::Some(crate::cmp::Ord::cmp(self, other))
}
}PartialOrd)]
41#[stable(feature = "rust1", since = "1.0.0")]
42#[cfg_attr(not(test), rustc_diagnostic_item = "io_errorkind")]
43#[allow(deprecated)]
44#[non_exhaustive]
45pub enum ErrorKind {
46/// An entity was not found, often a file.
47#[stable(feature = "rust1", since = "1.0.0")]
48NotFound,
49/// The operation lacked the necessary privileges to complete.
50#[stable(feature = "rust1", since = "1.0.0")]
51PermissionDenied,
52/// The connection was refused by the remote server.
53#[stable(feature = "rust1", since = "1.0.0")]
54ConnectionRefused,
55/// The connection was reset by the remote server.
56#[stable(feature = "rust1", since = "1.0.0")]
57ConnectionReset,
58/// The remote host is not reachable.
59#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
60HostUnreachable,
61/// The network containing the remote host is not reachable.
62#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
63NetworkUnreachable,
64/// The connection was aborted (terminated) by the remote server.
65#[stable(feature = "rust1", since = "1.0.0")]
66ConnectionAborted,
67/// The network operation failed because it was not connected yet.
68#[stable(feature = "rust1", since = "1.0.0")]
69NotConnected,
70/// A socket address could not be bound because the address is already in
71 /// use elsewhere.
72#[stable(feature = "rust1", since = "1.0.0")]
73AddrInUse,
74/// A nonexistent interface was requested or the requested address was not
75 /// local.
76#[stable(feature = "rust1", since = "1.0.0")]
77AddrNotAvailable,
78/// The system's networking is down.
79#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
80NetworkDown,
81/// The operation failed because a pipe was closed.
82#[stable(feature = "rust1", since = "1.0.0")]
83BrokenPipe,
84/// An entity already exists, often a file.
85#[stable(feature = "rust1", since = "1.0.0")]
86AlreadyExists,
87/// The operation needs to block to complete, but the blocking operation was
88 /// requested to not occur.
89#[stable(feature = "rust1", since = "1.0.0")]
90WouldBlock,
91/// A filesystem object is, unexpectedly, not a directory.
92 ///
93 /// For example, a filesystem path was specified where one of the intermediate directory
94 /// components was, in fact, a plain file.
95#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
96NotADirectory,
97/// The filesystem object is, unexpectedly, a directory.
98 ///
99 /// A directory was specified when a non-directory was expected.
100#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
101IsADirectory,
102/// A non-empty directory was specified where an empty directory was expected.
103#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
104DirectoryNotEmpty,
105/// The filesystem or storage medium is read-only, but a write operation was attempted.
106#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
107ReadOnlyFilesystem,
108/// Loop in the filesystem or IO subsystem; often, too many levels of symbolic links.
109 ///
110 /// There was a loop (or excessively long chain) resolving a filesystem object
111 /// or file IO object.
112 ///
113 /// On Unix this is usually the result of a symbolic link loop; or, of exceeding the
114 /// system-specific limit on the depth of symlink traversal.
115#[unstable(feature = "io_error_more", issue = "86442")]
116FilesystemLoop,
117/// Stale network file handle.
118 ///
119 /// With some network filesystems, notably NFS, an open file (or directory) can be invalidated
120 /// by problems with the network or server.
121#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
122StaleNetworkFileHandle,
123/// A parameter was incorrect.
124#[stable(feature = "rust1", since = "1.0.0")]
125InvalidInput,
126/// Data not valid for the operation were encountered.
127 ///
128 /// Unlike [`InvalidInput`], this typically means that the operation
129 /// parameters were valid, however the error was caused by malformed
130 /// input data.
131 ///
132 /// For example, a function that reads a file into a string will error with
133 /// `InvalidData` if the file's contents are not valid UTF-8.
134 ///
135 /// [`InvalidInput`]: ErrorKind::InvalidInput
136#[stable(feature = "io_invalid_data", since = "1.2.0")]
137InvalidData,
138/// The I/O operation's timeout expired, causing it to be canceled.
139#[stable(feature = "rust1", since = "1.0.0")]
140TimedOut,
141/// An error returned when an operation could not be completed because a
142 /// call to [`write`][write] returned [`Ok(0)`].
143 ///
144 /// This typically means that an operation could only succeed if it wrote a
145 /// particular number of bytes but only a smaller number of bytes could be
146 /// written.
147 ///
148 /// [write]: ../../std/io/trait.Write.html#tymethod.write
149 /// [`Ok(0)`]: Ok
150#[stable(feature = "rust1", since = "1.0.0")]
151WriteZero,
152/// The underlying storage (typically, a filesystem) is full.
153 ///
154 /// This does not include out of quota errors.
155#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
156StorageFull,
157/// Seek on unseekable file.
158 ///
159 /// Seeking was attempted on an open file handle which is not suitable for seeking - for
160 /// example, on Unix, a named pipe opened with `File::open`.
161#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
162NotSeekable,
163/// Filesystem quota or some other kind of quota was exceeded.
164#[stable(feature = "io_error_quota_exceeded", since = "1.85.0")]
165QuotaExceeded,
166/// File larger than allowed or supported.
167 ///
168 /// This might arise from a hard limit of the underlying filesystem or file access API, or from
169 /// an administratively imposed resource limitation. Simple disk full, and out of quota, have
170 /// their own errors.
171#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
172FileTooLarge,
173/// Resource is busy.
174#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
175ResourceBusy,
176/// Executable file is busy.
177 ///
178 /// An attempt was made to write to a file which is also in use as a running program. (Not all
179 /// operating systems detect this situation.)
180#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
181ExecutableFileBusy,
182/// Deadlock (avoided).
183 ///
184 /// A file locking operation would result in deadlock. This situation is typically detected, if
185 /// at all, on a best-effort basis.
186#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
187Deadlock,
188/// Cross-device or cross-filesystem (hard) link or rename.
189#[stable(feature = "io_error_crosses_devices", since = "1.85.0")]
190CrossesDevices,
191/// Too many (hard) links to the same filesystem object.
192 ///
193 /// The filesystem does not support making so many hardlinks to the same file.
194#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
195TooManyLinks,
196/// A filename was invalid.
197 ///
198 /// This error can also occur if a length limit for a name was exceeded.
199#[stable(feature = "io_error_invalid_filename", since = "1.87.0")]
200InvalidFilename,
201/// Program argument list too long.
202 ///
203 /// When trying to run an external program, a system or process limit on the size of the
204 /// arguments would have been exceeded.
205#[stable(feature = "io_error_a_bit_more", since = "1.83.0")]
206ArgumentListTooLong,
207/// This operation was interrupted.
208 ///
209 /// Interrupted operations can typically be retried.
210#[stable(feature = "rust1", since = "1.0.0")]
211Interrupted,
212213/// This operation is unsupported on this platform.
214 ///
215 /// This means that the operation can never succeed.
216#[stable(feature = "unsupported_error", since = "1.53.0")]
217Unsupported,
218219// ErrorKinds which are primarily categorisations for OS error
220 // codes should be added above.
221 //
222/// An error returned when an operation could not be completed because an
223 /// "end of file" was reached prematurely.
224 ///
225 /// This typically means that an operation could only succeed if it read a
226 /// particular number of bytes but only a smaller number of bytes could be
227 /// read.
228#[stable(feature = "read_exact", since = "1.6.0")]
229UnexpectedEof,
230231/// An operation could not be completed, because it failed
232 /// to allocate enough memory.
233#[stable(feature = "out_of_memory_error", since = "1.54.0")]
234OutOfMemory,
235236/// The operation was partially successful and needs to be checked
237 /// later on due to not blocking.
238#[unstable(feature = "io_error_inprogress", issue = "130840")]
239InProgress,
240241// "Unusual" error kinds which do not correspond simply to (sets
242 // of) OS error codes, should be added just above this comment.
243 // `Other` and `Uncategorized` should remain at the end:
244 //
245/// A custom error that does not fall under any other I/O error kind.
246 ///
247 /// This can be used to construct your own [`Error`][error]s that do not match any
248 /// [`ErrorKind`].
249 ///
250 /// This [`ErrorKind`] is not used by the standard library.
251 ///
252 /// Errors from the standard library that do not fall under any of the I/O
253 /// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern.
254 /// New [`ErrorKind`]s might be added in the future for some of those.
255 ///
256 /// [error]: ../../std/io/struct.Error.html
257#[stable(feature = "rust1", since = "1.0.0")]
258Other,
259260/// Any I/O error from the standard library that's not part of this list.
261 ///
262 /// Errors that are `Uncategorized` now may move to a different or a new
263 /// [`ErrorKind`] variant in the future. It is not recommended to match
264 /// an error against `Uncategorized`; use a wildcard match (`_`) instead.
265#[unstable(feature = "io_error_uncategorized", issue = "none")]
266 #[doc(hidden)]
267Uncategorized,
268}
269270impl ErrorKind {
271pub(crate) const fn as_str(&self) -> &'static str {
272use ErrorKind::*;
273match *self {
274// tidy-alphabetical-start
275AddrInUse => "address in use",
276AddrNotAvailable => "address not available",
277AlreadyExists => "entity already exists",
278ArgumentListTooLong => "argument list too long",
279BrokenPipe => "broken pipe",
280ConnectionAborted => "connection aborted",
281ConnectionRefused => "connection refused",
282ConnectionReset => "connection reset",
283CrossesDevices => "cross-device link or rename",
284Deadlock => "deadlock",
285DirectoryNotEmpty => "directory not empty",
286ExecutableFileBusy => "executable file busy",
287FileTooLarge => "file too large",
288FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
289HostUnreachable => "host unreachable",
290InProgress => "in progress",
291Interrupted => "operation interrupted",
292InvalidData => "invalid data",
293InvalidFilename => "invalid filename",
294InvalidInput => "invalid input parameter",
295IsADirectory => "is a directory",
296NetworkDown => "network down",
297NetworkUnreachable => "network unreachable",
298NotADirectory => "not a directory",
299NotConnected => "not connected",
300NotFound => "entity not found",
301NotSeekable => "seek on unseekable file",
302Other => "other error",
303OutOfMemory => "out of memory",
304PermissionDenied => "permission denied",
305QuotaExceeded => "quota exceeded",
306ReadOnlyFilesystem => "read-only filesystem or storage medium",
307ResourceBusy => "resource busy",
308StaleNetworkFileHandle => "stale network file handle",
309StorageFull => "no storage space",
310TimedOut => "timed out",
311TooManyLinks => "too many links",
312Uncategorized => "uncategorized error",
313UnexpectedEof => "unexpected end of file",
314Unsupported => "unsupported",
315WouldBlock => "operation would block",
316WriteZero => "write zero",
317// tidy-alphabetical-end
318}
319 }
320321// This compiles to the same code as the check+transmute, but doesn't require
322 // unsafe, or to hard-code max ErrorKind or its size in a way the compiler
323 // couldn't verify.
324#[inline]
325 #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
326 #[doc(hidden)]
327pub const fn from_prim(ek: u32) -> Option<Self> {
328macro_rules! from_prim {
329 ($prim:expr => $Enum:ident { $($Variant:ident),* $(,)? }) => {{
330// Force a compile error if the list gets out of date.
331const _: fn(e: $Enum) = |e: $Enum| match e {
332 $($Enum::$Variant => (),)*
333 };
334match $prim {
335 $(v if v == ($Enum::$Variant as _) => Some($Enum::$Variant),)*
336_ => None,
337 }
338 }}
339 }
340{
const _: fn(e: ErrorKind) =
|e: ErrorKind|
match e {
ErrorKind::NotFound => (),
ErrorKind::PermissionDenied => (),
ErrorKind::ConnectionRefused => (),
ErrorKind::ConnectionReset => (),
ErrorKind::HostUnreachable => (),
ErrorKind::NetworkUnreachable => (),
ErrorKind::ConnectionAborted => (),
ErrorKind::NotConnected => (),
ErrorKind::AddrInUse => (),
ErrorKind::AddrNotAvailable => (),
ErrorKind::NetworkDown => (),
ErrorKind::BrokenPipe => (),
ErrorKind::AlreadyExists => (),
ErrorKind::WouldBlock => (),
ErrorKind::NotADirectory => (),
ErrorKind::IsADirectory => (),
ErrorKind::DirectoryNotEmpty => (),
ErrorKind::ReadOnlyFilesystem => (),
ErrorKind::FilesystemLoop => (),
ErrorKind::StaleNetworkFileHandle => (),
ErrorKind::InvalidInput => (),
ErrorKind::InvalidData => (),
ErrorKind::TimedOut => (),
ErrorKind::WriteZero => (),
ErrorKind::StorageFull => (),
ErrorKind::NotSeekable => (),
ErrorKind::QuotaExceeded => (),
ErrorKind::FileTooLarge => (),
ErrorKind::ResourceBusy => (),
ErrorKind::ExecutableFileBusy => (),
ErrorKind::Deadlock => (),
ErrorKind::CrossesDevices => (),
ErrorKind::TooManyLinks => (),
ErrorKind::InvalidFilename => (),
ErrorKind::ArgumentListTooLong => (),
ErrorKind::Interrupted => (),
ErrorKind::Other => (),
ErrorKind::UnexpectedEof => (),
ErrorKind::Unsupported => (),
ErrorKind::OutOfMemory => (),
ErrorKind::InProgress => (),
ErrorKind::Uncategorized => (),
};
match ek {
v if v == (ErrorKind::NotFound as _) => Some(ErrorKind::NotFound),
v if v == (ErrorKind::PermissionDenied as _) =>
Some(ErrorKind::PermissionDenied),
v if v == (ErrorKind::ConnectionRefused as _) =>
Some(ErrorKind::ConnectionRefused),
v if v == (ErrorKind::ConnectionReset as _) =>
Some(ErrorKind::ConnectionReset),
v if v == (ErrorKind::HostUnreachable as _) =>
Some(ErrorKind::HostUnreachable),
v if v == (ErrorKind::NetworkUnreachable as _) =>
Some(ErrorKind::NetworkUnreachable),
v if v == (ErrorKind::ConnectionAborted as _) =>
Some(ErrorKind::ConnectionAborted),
v if v == (ErrorKind::NotConnected as _) =>
Some(ErrorKind::NotConnected),
v if v == (ErrorKind::AddrInUse as _) => Some(ErrorKind::AddrInUse),
v if v == (ErrorKind::AddrNotAvailable as _) =>
Some(ErrorKind::AddrNotAvailable),
v if v == (ErrorKind::NetworkDown as _) =>
Some(ErrorKind::NetworkDown),
v if v == (ErrorKind::BrokenPipe as _) => Some(ErrorKind::BrokenPipe),
v if v == (ErrorKind::AlreadyExists as _) =>
Some(ErrorKind::AlreadyExists),
v if v == (ErrorKind::WouldBlock as _) => Some(ErrorKind::WouldBlock),
v if v == (ErrorKind::NotADirectory as _) =>
Some(ErrorKind::NotADirectory),
v if v == (ErrorKind::IsADirectory as _) =>
Some(ErrorKind::IsADirectory),
v if v == (ErrorKind::DirectoryNotEmpty as _) =>
Some(ErrorKind::DirectoryNotEmpty),
v if v == (ErrorKind::ReadOnlyFilesystem as _) =>
Some(ErrorKind::ReadOnlyFilesystem),
v if v == (ErrorKind::FilesystemLoop as _) =>
Some(ErrorKind::FilesystemLoop),
v if v == (ErrorKind::StaleNetworkFileHandle as _) =>
Some(ErrorKind::StaleNetworkFileHandle),
v if v == (ErrorKind::InvalidInput as _) =>
Some(ErrorKind::InvalidInput),
v if v == (ErrorKind::InvalidData as _) =>
Some(ErrorKind::InvalidData),
v if v == (ErrorKind::TimedOut as _) => Some(ErrorKind::TimedOut),
v if v == (ErrorKind::WriteZero as _) => Some(ErrorKind::WriteZero),
v if v == (ErrorKind::StorageFull as _) =>
Some(ErrorKind::StorageFull),
v if v == (ErrorKind::NotSeekable as _) =>
Some(ErrorKind::NotSeekable),
v if v == (ErrorKind::QuotaExceeded as _) =>
Some(ErrorKind::QuotaExceeded),
v if v == (ErrorKind::FileTooLarge as _) =>
Some(ErrorKind::FileTooLarge),
v if v == (ErrorKind::ResourceBusy as _) =>
Some(ErrorKind::ResourceBusy),
v if v == (ErrorKind::ExecutableFileBusy as _) =>
Some(ErrorKind::ExecutableFileBusy),
v if v == (ErrorKind::Deadlock as _) => Some(ErrorKind::Deadlock),
v if v == (ErrorKind::CrossesDevices as _) =>
Some(ErrorKind::CrossesDevices),
v if v == (ErrorKind::TooManyLinks as _) =>
Some(ErrorKind::TooManyLinks),
v if v == (ErrorKind::InvalidFilename as _) =>
Some(ErrorKind::InvalidFilename),
v if v == (ErrorKind::ArgumentListTooLong as _) =>
Some(ErrorKind::ArgumentListTooLong),
v if v == (ErrorKind::Interrupted as _) =>
Some(ErrorKind::Interrupted),
v if v == (ErrorKind::Other as _) => Some(ErrorKind::Other),
v if v == (ErrorKind::UnexpectedEof as _) =>
Some(ErrorKind::UnexpectedEof),
v if v == (ErrorKind::Unsupported as _) =>
Some(ErrorKind::Unsupported),
v if v == (ErrorKind::OutOfMemory as _) =>
Some(ErrorKind::OutOfMemory),
v if v == (ErrorKind::InProgress as _) => Some(ErrorKind::InProgress),
v if v == (ErrorKind::Uncategorized as _) =>
Some(ErrorKind::Uncategorized),
_ => None,
}
}from_prim!(ek => ErrorKind {
341 NotFound,
342 PermissionDenied,
343 ConnectionRefused,
344 ConnectionReset,
345 HostUnreachable,
346 NetworkUnreachable,
347 ConnectionAborted,
348 NotConnected,
349 AddrInUse,
350 AddrNotAvailable,
351 NetworkDown,
352 BrokenPipe,
353 AlreadyExists,
354 WouldBlock,
355 NotADirectory,
356 IsADirectory,
357 DirectoryNotEmpty,
358 ReadOnlyFilesystem,
359 FilesystemLoop,
360 StaleNetworkFileHandle,
361 InvalidInput,
362 InvalidData,
363 TimedOut,
364 WriteZero,
365 StorageFull,
366 NotSeekable,
367 QuotaExceeded,
368 FileTooLarge,
369 ResourceBusy,
370 ExecutableFileBusy,
371 Deadlock,
372 CrossesDevices,
373 TooManyLinks,
374 InvalidFilename,
375 ArgumentListTooLong,
376 Interrupted,
377 Other,
378 UnexpectedEof,
379 Unsupported,
380 OutOfMemory,
381 InProgress,
382 Uncategorized,
383 })384 }
385}
386387#[stable(feature = "io_errorkind_display", since = "1.60.0")]
388impl fmt::Displayfor ErrorKind {
389/// Shows a human-readable description of the [`ErrorKind`].
390 ///
391 /// This is similar to `impl Display for Error`, but doesn't require first converting to Error.
392 ///
393 /// # Examples
394 /// ```
395 /// use core::io::ErrorKind;
396 /// assert_eq!("entity not found", ErrorKind::NotFound.to_string());
397 /// ```
398fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
399fmt.write_str(self.as_str())
400 }
401}