Trait common_failures::io::IoContextExt [] [src]

pub trait IoContextExt<T, E>: Sized {
    fn io_context<Tgt>(
        self,
        operation: Operation,
        target: Tgt
    ) -> Result<T, Context<IoError>>
    where
        Tgt: Into<Target>
; fn io_read_context<Tgt>(self, target: Tgt) -> Result<T, Context<IoError>>
    where
        Tgt: Into<Target>
, { ... }
fn io_write_context<Tgt>(self, target: Tgt) -> Result<T, Context<IoError>>
    where
        Tgt: Into<Target>
, { ... } }

Trait which extends Result with methods for generating better error messages.

Required Methods

Specify the "context" within which an I/O operation occurred. Will be used to generate a human-readable error message if needed.

use common_failures::prelude::*;
use common_failures::io::{Operation, Target};
use std::fs::create_dir_all;
use std::path::Path;

fn create_directory(path: &Path) -> Result<()> {
    create_dir_all(path).io_context(
        Operation::Create,
        Target::Directory(path.to_owned()),
    )?;
    Ok(())
}

Provided Methods

Specify the "context" within which an I/O read operation occurred. Will be used to generate a human-readable error message if needed.

use common_failures::prelude::*;
use std::fs::File;
use std::path::Path;

fn open_example(path: &Path) -> Result<File> {
    Ok(File::open(path).io_read_context(path)?)
}

Specify the "context" within which an I/O write operation occurred. Will be used to generate a human-readable error message if needed.

Implementations on Foreign Types

impl<T, E> IoContextExt<T, E> for Result<T, E> where
    E: Fail
[src]

[src]

[src]

[src]

Implementors