[][src]Trait io_result_optional::IoResultOptional

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

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

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();
Loading content...

Implementations on Foreign Types

impl<T> IoResultOptional<T> for Result<T>
[src]

Loading content...

Implementors

Loading content...