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
| Property | Type | Notes |
|---|---|---|
kind | IoErrorKind | |
os_code | i32 | errno 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;
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;
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
| Variant | Notes |
|---|---|
NotFound | |
PermissionDenied | |
AlreadyExists | |
ConnectionRefused | |
ConnectionReset | |
ConnectionAborted | |
NotConnected | |
AddrInUse | |
AddrNotAvailable | |
BrokenPipe | |
Interrupted | |
InvalidInput | |
InvalidData | |
TimedOut | |
WriteZero | |
UnexpectedEof | |
WouldBlock | |
OutOfMemory | |
Unsupported | The 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). |
Other | A platform-specific errno that doesn't map to any of the above. os_code is the authoritative detail. |
Methods
label(&this) -> string;
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;type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct IoError {
kind: IoErrorKind;
os_code: i32;
}IoError.kind: IoErrorKindtype enum IoErrorKind {
NotFound;
PermissionDenied;
AlreadyExists;
ConnectionRefused;
ConnectionReset;
ConnectionAborted;
NotConnected;
AddrInUse;
AddrNotAvailable;
BrokenPipe;
// … 10 more
}IoError.os_code: i32errno from the underlying syscall, or 0 if not applicable. Useful for diagnostics; callers should branch on kind.
static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static IoError::new(kind: IoErrorKind, os_code: i32) -> IoError(parameter) kind: IoErrorKind(parameter) os_code: i32type struct IoError {
kind: IoErrorKind;
os_code: i32;
}IoError::describe(&this) -> str::StrA 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.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
static IoError::from_errno(code: i32) -> IoErrorMap a POSIX errno to an IoError. Unknown codes fold to Other with the numeric code preserved in os_code.
(parameter) code: i32type enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum IoErrorKind {
NotFound;
PermissionDenied;
AlreadyExists;
ConnectionRefused;
ConnectionReset;
ConnectionAborted;
NotConnected;
AddrInUse;
AddrNotAvailable;
BrokenPipe;
// … 10 more
}IoErrorKind::NotFoundIoErrorKind::PermissionDeniedIoErrorKind::AlreadyExistsIoErrorKind::ConnectionRefusedIoErrorKind::ConnectionResetIoErrorKind::ConnectionAbortedIoErrorKind::NotConnectedIoErrorKind::AddrInUseIoErrorKind::AddrNotAvailableIoErrorKind::BrokenPipeIoErrorKind::InterruptedIoErrorKind::InvalidInputIoErrorKind::InvalidDataIoErrorKind::TimedOutIoErrorKind::WriteZeroIoErrorKind::UnexpectedEofIoErrorKind::WouldBlockIoErrorKind::OutOfMemoryIoErrorKind::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).
IoErrorKind::OtherA platform-specific errno that doesn't map to any of the above. os_code is the authoritative detail.
implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement enum Name { ... }Names the enum an inherent block extends - the only way to give an enum methods.
language referenceIoErrorKind::label(&this) -> stringShort, stable diagnostic slug: "not_found", "permission_denied", etc. Mirrors JsonErrorKind::label. Returns a static string literal (no allocation, nothing to drop).
primitive stringNUL-terminated raw string (u8*), matching the C ABI. Length-typed text is Str / String.
const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
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;const EADDRINUSE: i32 = 98;const EADDRNOTAVAIL: i32 = 99;const ECONNABORTED: i32 = 103;const ECONNRESET: i32 = 104;const ENOTCONN: i32 = 107;const ETIMEDOUT: i32 = 110;const ECONNREFUSED: i32 = 111;import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
IoError.kind: IoErrorKindIoError.os_code: i32errno from the underlying syscall, or 0 if not applicable. Useful for diagnostics; callers should branch on kind.
IoError::describe(&this) -> str::StrA 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.
type struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strIoErrorKind::label(&this) -> stringShort, stable diagnostic slug: "not_found", "permission_denied", etc. Mirrors JsonErrorKind::label. Returns a static string literal (no allocation, nothing to drop).
static IoError::from_errno(code: i32) -> IoErrorMap a POSIX errno to an IoError. Unknown codes fold to Other with the numeric code preserved in os_code.
IoErrorKind::OtherA platform-specific errno that doesn't map to any of the above. os_code is the authoritative detail.
static IoError::new(kind: IoErrorKind, os_code: i32) -> IoErrortype trait Display {
fmt<W>(&this, f: mut &Formatter<W>) -> Result<(), FmtError>
where W: FmtWrite;
}Display / Debug / Formatter.
std::fmt::displaytype trait Debug {
fmt<W>(&this, f: mut &Formatter<W>) -> Result<(), FmtError>
where W: FmtWrite;
}const EADDRINUSE: i32 = 98;namespace std::net::sys;net::sys: per-OS socket primitives behind a uniform interface.
extern "C" function WSAGetLastError() -> i32const ENOENT: i32 = 2;const EINTR: i32 = 4;const EPIPE: i32 = 32;IoErrorKind::NotFoundIoErrorKind::PermissionDeniedIoErrorKind::AlreadyExistsIoErrorKind::ConnectionRefusedIoErrorKind::ConnectionResetIoErrorKind::ConnectionAbortedIoErrorKind::NotConnectedIoErrorKind::AddrInUseIoErrorKind::AddrNotAvailableIoErrorKind::BrokenPipeIoErrorKind::InterruptedIoErrorKind::InvalidInputIoErrorKind::InvalidDataIoErrorKind::TimedOutIoErrorKind::WriteZeroIoErrorKind::UnexpectedEofIoErrorKind::WouldBlockIoErrorKind::OutOfMemoryIoErrorKind::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).
type enum JsonErrorKind {
UnexpectedEof;
UnexpectedChar;
InvalidNumber;
InvalidEscape;
InvalidUnicode;
DepthExceeded;
TrailingData;
KeyNotString;
OutOfMemory;
}Closed set of failure kinds the JSON parser produces. New kinds are rare; most failures fold into one of these.
std::json::errorJsonErrorKind::label(&this) -> stringShort slug for diagnostics. "unexpected_eof", "invalid_number", etc.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referenceimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language reference