error
import std::fmt::error; · source
Types
FmtError
type enum FmtError {
Io(IoError);
Alloc(AllocError);
}
implement enum FmtError {
is_io(&this) -> boolean;
is_alloc(&this) -> boolean;
describe(&this) -> Str;
}
A formatted write can fail two ways, and collapsing them would throw away information a caller might want to branch on — a format that failed because String::push couldn't reallocate is not the same shape of problem as a closed socket. describe forwards to the wrapped error's own describe.
Variants
| Variant | Notes |
|---|---|
Io(IoError) | The byte sink rejected the write. IoError carries kind + errno. |
Alloc(AllocError) | A heap-backed sink (String, Array<u8>) could not grow. |
Methods
is_io(&this) -> boolean;
is_alloc(&this) -> boolean;
describe(&this) -> Str;
describe(&this) -> Str;A short, stable description of what went wrong, as a borrowed Str. The convergent accessor every stdlib error type exposes (describe(&this) -> Str); Display/Debug for FmtError delegate to it. Forwards to the wrapped error's own describe, so the variant (I/O vs allocation) is reflected without duplicating text here.
Trait implementations
implement trait From<IoError> for enum FmtError
implement trait From<AllocError> for enum FmtError
implement trait Display for enum FmtError
std::fmt::display
implement trait Debug for enum FmtError
std::fmt::display
The two From impls are the lifting conversions sink implementations use, which is what lets ? on an io::Write call inside a FmtWrite impl just work.
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 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 FmtError {
Io(IoError);
Alloc(AllocError);
}FmtError::Io(IoError)The byte sink rejected the write. IoError carries kind + errno.
type struct IoError {
kind: IoErrorKind;
os_code: i32;
}FmtError::Alloc(AllocError)A heap-backed sink (String, Array<u8>) could not grow.
type struct AllocError {
kind: AllocErrorKind;
layout: Layout;
}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 referencetype enum FmtError {
Io(IoError);
Alloc(AllocError);
}FmtError::is_io(&this) -> boolean&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.
FmtError::is_alloc(&this) -> booleanFmtError::describe(&this) -> StrA short, stable description of what went wrong, as a borrowed Str. The convergent accessor every stdlib error type exposes (describe(&this) -> Str); Display/Debug for FmtError delegate to it.
type struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strimport 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).
type struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
std::collections::stringString::push<T>(mut &this, item: T) -> voidAppend item to the string as its **text** representation, dispatched at compile time via static match (T) - no runtime cost, no trait bound, because the available arms ARE the accepted types: - Str / string - the view's / C string's UTF-8 bytes verbatim (a string's terminating NUL is not copied).
FmtError::describe(&this) -> StrA short, stable description of what went wrong, as a borrowed Str. The convergent accessor every stdlib error type exposes (describe(&this) -> Str); Display/Debug for FmtError delegate to it.
type struct Array<T, A = GlobalAlloc> where A: Allocator {
ptr: T*;
length: i64;
capacity: i64;
alloc: A;
}Array<T, A>: growable, heap-backed, contiguous sequence.
std::collections::arrayFmtError::is_io(&this) -> booleanFmtError::is_alloc(&this) -> booleantype 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;
}implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referencetype trait From<T> {
static from(value: T) -> This;
}implement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype trait Write {
write_some(mut &this, bytes: Slice<u8>) -> Result<u64, IoError>;
flush(mut &this) -> Result<(), IoError>;
write<T>(mut &this, data: T) -> Result<(), IoError>;
}type trait FmtWrite {
write_str(mut &this, source: Str) -> Result<(), FmtError>;
write_char(mut &this, c: char) -> Result<(), FmtError>;
}