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§
Sourcefn not_found_as(self, kind: NotFound) -> ErrorKind
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,
))
})?;