Trait IoResultExt

Source
pub trait IoResultExt<T>: Sealed + Sized {
    // Required methods
    fn optional(self) -> Result<Option<T>>;
    fn can_exist(self) -> Self
       where T: Default;
}
Expand description

A collection of helper methods for std::io::Result.

Required Methods§

Source

fn optional(self) -> Result<Option<T>>

Map potentially not found entities to an Option.

if let Some(config) = File::open("config.json").optional()? {
    // do something...
}
Source

fn can_exist(self) -> Self
where T: Default,

Mask ErrorKind::AlreadyExists errors.

fs::create_dir("cache").can_exist()?;
// And then on a later run...
fs::create_dir("cache").can_exist()?;

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> IoResultExt<T> for Result<T>

Source§

fn optional(self) -> Result<Option<T>>

Source§

fn can_exist(self) -> Self
where T: Default,

Implementors§