Tutorial by Examples

use std::io::{Read, Result as IoResult}; use std::fs::File; struct Config(u8); fn read_config() -> IoResult<String> { let mut s = String::new(); let mut file = File::open(&get_local_config_path()) // or_else closure is invoked if Result is Err. .or_els...
use std::error::Error; use std::fmt; use std::convert::From; use std::io::Error as IoError; use std::str::Utf8Error; #[derive(Debug)] // Allow the use of "{:?}" format specifier enum CustomError { Io(IoError), Utf8(Utf8Error), Other, } // Allow the use of "{...
It is often useful for debugging purposes to find the root cause of an error. In order to examine an error value that implements std::error::Error: use std::error::Error; let orig_error = call_returning_error(); // Use an Option<&Error>. This is the return type of Error.cause(). le...
Result<T, E> is an enum type which has two variants: Ok(T) indicating successful execution with meaningful result of type T, and Err(E) indicating occurrence of an unexpected error during execution, described by a value of type E. enum DateError { InvalidDay, InvalidMonth, } str...

Page 1 of 1