pub trait IoResultOptional<T> {
// Required method
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§
Sourcefn optional(self) -> Result<Option<T>>
fn optional(self) -> Result<Option<T>>
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();