]> git.lizzy.rs Git - rust.git/commitdiff
ErrorKind: Reformat the mapping table (unix)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 3 Dec 2020 20:39:33 +0000 (20:39 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 18 Jun 2021 16:45:04 +0000 (17:45 +0100)
* Sort the single matches alphabetically.
* use ErrorKind::*;

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
library/std/src/sys/unix/mod.rs

index 21c718825b889c6081a8934068460dc990ad01c8..387067a505b091265d62d605f26ff6e780f54aec 100644 (file)
@@ -133,29 +133,31 @@ pub unsafe fn cleanup() {
 pub use libc::signal;
 
 pub fn decode_error_kind(errno: i32) -> ErrorKind {
+    use ErrorKind::*;
     match errno as libc::c_int {
-        libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
-        libc::ECONNRESET => ErrorKind::ConnectionReset,
-        libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
-        libc::EPIPE => ErrorKind::BrokenPipe,
-        libc::ENOTCONN => ErrorKind::NotConnected,
-        libc::ECONNABORTED => ErrorKind::ConnectionAborted,
-        libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
-        libc::EADDRINUSE => ErrorKind::AddrInUse,
-        libc::ENOENT => ErrorKind::NotFound,
-        libc::EINTR => ErrorKind::Interrupted,
-        libc::EINVAL => ErrorKind::InvalidInput,
-        libc::ETIMEDOUT => ErrorKind::TimedOut,
-        libc::EEXIST => ErrorKind::AlreadyExists,
-        libc::ENOSYS => ErrorKind::Unsupported,
-        libc::ENOMEM => ErrorKind::OutOfMemory,
+        libc::EADDRINUSE => AddrInUse,
+        libc::EADDRNOTAVAIL => AddrNotAvailable,
+        libc::ECONNABORTED => ConnectionAborted,
+        libc::ECONNREFUSED => ConnectionRefused,
+        libc::ECONNRESET => ConnectionReset,
+        libc::EEXIST => AlreadyExists,
+        libc::EINTR => Interrupted,
+        libc::EINVAL => InvalidInput,
+        libc::ENOENT => NotFound,
+        libc::ENOMEM => OutOfMemory,
+        libc::ENOSYS => Unsupported,
+        libc::ENOTCONN => NotConnected,
+        libc::EPIPE => BrokenPipe,
+        libc::ETIMEDOUT => TimedOut,
+
+        libc::EACCES | libc::EPERM  => PermissionDenied,
 
         // These two constants can have the same value on some systems,
         // but different values on others, so we can't use a match
         // clause
-        x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock,
+        x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => WouldBlock,
 
-        _ => ErrorKind::Uncategorized,
+        _ => Uncategorized,
     }
 }