全部书籍

专业

应用 关于 Coach 登录 开始阅读

书籍暂未推出简体中文版——当前显示英文版。

Computer Science · 术语表

什么是 Result type, error propagation?

又称: result type · error propagation

Definition 7.7 University Computer Science — Year 2 · 第 7 章 — Enums, Pattern Matching and Error Handling

The result type Result<T, E> is the enum with the variants Ok(T), a success carrying its value, and Err(E), a failure carrying an error of type E. Error propagation is the return of a failure to the caller: the operator ? applied to a Result gives the value inside Ok, or returns Err(e) from the enclosing function at once, converting e with From::from into that function’s error type.

Two errors travelling back. Above, the missing file: ? converts the io::Error and returns it from read_log, and main reports it. Below, a missing temperature: ? in parse_line skips the remaining fields, and read_log, which matches instead of using ?, records the error and reads the next line.
Two errors travelling back. Above, the missing file: ? converts the io::Error and returns it from read_log, and main reports it. Below, a missing temperature: ? in parse_line skips the remaining fields, and read_log, which matches instead of using ?, records the error and reads the next line.
在原文中阅读 →