pub trait IoResultOptional<T> {
    fn optional(self) -> Result<Option<T>>;
}
Expand description

A trait for io::Result that adds a method making it easy to tell the difference between a file not found and another error, since a common practice is to handle a file if it exists.

Required Methods§

Consider the given file access optional. if the result is an error with io::ErrorKind NotFound, convert it to Ok(None). If it is any other error, return it as-is, and if it is Ok(value) convert it to Ok(Some(value)).

Examples
use std::fs::File;
use io_result_optional::IoResultOptional;

let config = File::open(".app.rc")
    .optional()?
    .map(parseconfig)
    .unwrap_or_default();

Implementations on Foreign Types§

Implementors§