Tous les livres

Professionnel

Applis À propos Coach Connexion Commencer la lecture

Computer Science · Glossaire

Qu'est-ce que « Result type, error propagation » ?

Aussi appelé : result type · error propagation

Definition 7.7 University Computer Science — Year 2 · Chapitre 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.
Lire dans le chapitre →