docs

core::error

本页内容

API 参考只有英文版,由标准库源代码中的英文文档注释生成。

Result<T, E>, an error kept as a value. Errors travel through throws / try; Result is for holding one (collected results, callbacks, caches): "throw it: throws; keep it: Result". ? does not apply to it (T | none only).

Ok / Err are bare names where a Result is expected (the expected type picks the variant).

Structs

ParseErrorSource

pub struct ParseError

A str that is not a valid value of the requested type (thrown by str::parse / FromStr).

  • pub const fn new(input: str, position: usize, message: str) -> ParseError§

    Source

    input failed at byte position because of message.

  • pub const fn input(self) -> str§

    Source

    The text that did not parse.

  • pub const fn position(self) -> usize§

    Source

    The byte offset in input where parsing failed.

  • pub const fn message(self) -> str§

    Source

    Why it failed, without the input Display adds.

Trait implementations 3
  • impl Display for ParseError
  • impl Debug for ParseError
  • impl Error for ParseError

ValueErrorSource

pub struct ValueError

An invalid argument value (FormatSpec::parse, hkdf::expand, ...).

  • pub const fn new(message: str) -> ValueError§

    Source

    An error saying message.

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 3
  • impl Display for ValueError
  • impl Debug for ValueError
  • impl Error for ValueError

OverflowErrorSource

pub struct OverflowError

A value out of a fixed-width type's range in a checked conversion (thrown by try_from / try_into).

  • pub const fn new(operation: str, type_name: str) -> OverflowError§

    Source

    operation ("try_from", ...) overflowed target type type_name ("i32", ...).

  • pub const fn operation(self) -> str§

    Source

    The operation that overflowed: "try_from", ...

  • pub const fn type_name(self) -> str§

    Source

    The target type: "i32", ...

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 3
  • impl Display for OverflowError
  • impl Debug for OverflowError
  • impl Error for OverflowError

ConversionErrorSource

pub struct ConversionError

A failed TryFrom conversion: the trait's default Error for impls that name no more specific one.

  • pub const fn new(message: str) -> ConversionError§

    Source

    An error saying message.

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 3
  • impl Display for ConversionError
  • impl Debug for ConversionError
  • impl Error for ConversionError

TypeErrorSource

pub struct TypeError

A value of the wrong type.

  • pub const fn new(expected: str, actual: str) -> TypeError§

    Source

    A mismatch: expected was wanted, actual was found.

  • pub const fn expected(self) -> str§

    Source

    The type that was wanted.

  • pub const fn actual(self) -> str§

    Source

    The type that was found.

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 3
  • impl Display for TypeError
  • impl Debug for TypeError
  • impl Error for TypeError

StackOverflowErrorSource

pub struct StackOverflowError

Fatal: the stack ran out. Never thrown; the runtime reports it and exits with 101.

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 3
  • impl Display for StackOverflowError
  • impl Debug for StackOverflowError
  • impl Error for StackOverflowError

OutOfMemoryErrorSource

pub struct OutOfMemoryError

Fatal: an allocation failed. Never thrown; the runtime reports it and exits with 101.

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 3
  • impl Display for OutOfMemoryError
  • impl Debug for OutOfMemoryError
  • impl Error for OutOfMemoryError

InternalErrorSource

pub struct InternalError

Fatal: a compiler bug reached at run time. Never thrown; the runtime reports it and exits with 101.

  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 3
  • impl Display for InternalError
  • impl Debug for InternalError
  • impl Error for InternalError

Enums

ResultSource

pub enum Result<T, E>

A value or an error, kept as a value: Ok(T) or Err(E).

  • Err(E)§

    Source
  • pub const fn catching(f: fn() throws (E) -> T) -> Result<T, E>§

    Source

    Run f, keeping its value or its error.

  • pub const fn is_ok(self) -> bool§

    Source

    true for Ok.

  • pub const fn is_err(self) -> bool§

    Source

    true for Err.

  • pub const fn ok(self) -> T | none§

    Source

    The value, or none when self is Err.

  • pub fn err(self) -> E | none§

    Source

    The error, or none when self is Ok.

  • pub const fn get(self) throws (E) -> T§

    Source

    Back into the error flow: the value, or throw the error.

  • pub const fn unwrap(self) -> T§

    Source

    The value; panics on Err, showing the error.

  • pub const fn unwrap_or(self, default: T) -> T§

    Source

    The value, or default on Err.

  • pub const fn unwrap_or_else(self, f: fn(E) -> T) -> T§

    Source

    The value, or f of the error on Err.

  • pub const fn map<U>(self, f: fn(T) -> U) -> Result<U, E>§

    Source

    f applied to the value; an Err passes through.

  • pub const fn map_err<F>(self, f: fn(E) -> F) -> Result<T, F>§

    Source

    f applied to the error; an Ok passes through.

  • pub const fn and_then<U>(self, f: fn(T) -> Result<U, E>) -> Result<U, E>§

    Source

    f of the value on Ok; an Err passes through.

  • pub const fn or_else<F>(self, f: fn(E) -> Result<T, F>) -> Result<T, F>§

    Source

    f of the error on Err; an Ok passes through.

Trait implementations 1

Traits

ErrorSource

pub trait Error: Display + Debug

Every error type's surface. Untyped throws means throws (any Error).

  • const fn source(self) -> any Error | none§

    Source

    The error that caused this one, if any.