Trait ErrorKindExt

Source
pub trait ErrorKindExt {
    // Required method
    fn not_found_as(self, kind: NotFound) -> ErrorKind;
}
Expand description

Extension trait for working with std::io::ErrorKind.

Required Methods§

Source

fn not_found_as(self, kind: NotFound) -> ErrorKind

Map NotFound variants into more precise variants.

The OS doesn’t know when an entity was not found whether it was meant to be a file or a directory or something else. But sometimes we, the application, know what we expect and with this method, we can further specify it.

§Examples

Reading a file. If the file isn’t found, return FileNotFound.

let a_file = PathBuf::from("scripts/ellie.nu");
let ellie = fs::read_to_string(&a_file).map_err(|err| {
    ShellError::Io(IoError::new(
        err.kind().not_found_as(NotFound::File),
        span,
        a_file,
    ))
})?;

Implementations on Foreign Types§

Source§

impl ErrorKindExt for ErrorKind

Implementors§

Source§

impl ErrorKindExt for nu_engine::command_prelude::ErrorKind