Skip to content
CryoCryo home

error

import std::io::error; · source

Types

IoError

type struct IoError {
    kind:    IoErrorKind;
    os_code: i32;

    static new(kind: IoErrorKind, os_code: i32) -> IoError;
    describe(&this) -> str::Str;
    static from_errno(code: i32) -> IoError;
}

IoError carries the kind plus os_code, the underlying errno (or 0 where not applicable). Branch on the kind; keep the code for diagnostics. describe() -> Str is the standard accessor, and IoErrorKind::label() gives a stable slug like "not_found".

from_errno(code) does the mapping. Unknown codes fold to Other with the numeric value preserved.

Properties

PropertyTypeNotes
kindIoErrorKind
os_codei32errno from the underlying syscall, or 0 if not applicable. Useful for diagnostics; callers should branch on kind.

Constructors

static new(kind: IoErrorKind, os_code: i32) -> IoError;
static from_errno(code: i32) -> IoError;

Map a POSIX errno to an IoError. Unknown codes fold to Other with the numeric code preserved in os_code.

Methods

describe(&this) -> str::Str;

A short, stable description of what went wrong, as a borrowed Str. This is the convergent accessor every stdlib error type exposes (describe(&this) -> Str); Display/Debug for IoError delegate to it. Backed by the kind's diagnostic slug (e.g. "not_found"); the numeric OS code lives in os_code for callers that want to print it alongside. Borrows a static string literal, so the view outlives any IoError.

IoErrorKind

type enum IoErrorKind {
    NotFound;
    PermissionDenied;
    AlreadyExists;
    ConnectionRefused;
    ConnectionReset;
    ConnectionAborted;
    NotConnected;
    AddrInUse;
    AddrNotAvailable;
    BrokenPipe;
    Interrupted;
    InvalidInput;
    InvalidData;
    TimedOut;
    WriteZero;
    UnexpectedEof;
    WouldBlock;
    OutOfMemory;
    Unsupported;
    Other;
}

implement enum IoErrorKind {
    label(&this) -> string;
}

A small closed set of kinds, because callers mostly branch on the kind rather than the text.

The errno table is gated per OS. from_errno is fed msvcrt's C-runtime errno on Windows and glibc's on Linux; the base codes (1–34) are identical, but the socket range differs — EADDRINUSE is 98 on glibc and 100 on msvcrt — so those are gated. Socket errors on Windows do not pass through here at all; net::sys maps WSAGetLastError() codes directly. The named constants (ENOENT, EINTR, EPIPE, EADDRINUSE, ...) live in this module.

Variants
VariantNotes
NotFound
PermissionDenied
AlreadyExists
ConnectionRefused
ConnectionReset
ConnectionAborted
NotConnected
AddrInUse
AddrNotAvailable
BrokenPipe
Interrupted
InvalidInput
InvalidData
TimedOut
WriteZero
UnexpectedEof
WouldBlock
OutOfMemory
UnsupportedThe operation is recognized but not implemented on this build (e.g. a feature stubbed pending implementation, or a platform the stdlib doesn't support yet). Distinct from InvalidInput (caller's fault) and Other (unmapped errno).
OtherA platform-specific errno that doesn't map to any of the above. os_code is the authoritative detail.
Methods
label(&this) -> string;

Short, stable diagnostic slug: "not_found", "permission_denied", etc. Mirrors JsonErrorKind::label. Returns a static string literal (no allocation, nothing to drop).

Trait implementations

implement trait Display for struct IoError
std::fmt::display
implement trait Debug for struct IoError
std::fmt::display

Constants

const ENOENT: i32 = 2;
const EINTR:  i32 = 4;
const EIO:    i32 = 5;
const EAGAIN: i32 = 11;
const ENOMEM: i32 = 12;
const EACCES: i32 = 13;
const EEXIST: i32 = 17;
const EINVAL: i32 = 22;
const EPIPE:  i32 = 32;

![target(linux)]
const EADDRINUSE: i32 = 98;

![target(windows)]
const EADDRINUSE: i32 = 100;

![target(linux)]
const EADDRNOTAVAIL: i32 = 99;

![target(windows)]
const EADDRNOTAVAIL: i32 = 101;

![target(linux)]
const ECONNABORTED: i32 = 103;

![target(windows)]
const ECONNABORTED: i32 = 106;

![target(linux)]
const ECONNRESET: i32 = 104;

![target(windows)]
const ECONNRESET: i32 = 108;

![target(linux)]
const ENOTCONN: i32 = 107;

![target(windows)]
const ENOTCONN: i32 = 128;

![target(linux)]
const ETIMEDOUT: i32 = 110;

![target(windows)]
const ETIMEDOUT: i32 = 138;

![target(linux)]
const ECONNREFUSED: i32 = 111;

![target(windows)]
const ECONNREFUSED: i32 = 107;