glob
glob copied to clipboard
add `From<GlobError> for io::Error` impl
The conversion I would suggest is:
impl From<GlobError> for io::Error {
fn from(err: GobError) -> io::Error {
io::Error::new(err.error.kind(), err)
}
}
This will keep the "pretty context" so that glob errors keep printing as:
"attempting to read `{}` resulted in an error: {}",
self.path.display(),
self.error
Which is already very ergonomic.
I can do this if you OK it :smile:
Benefits / Justification
The glob error is already essentially an io::Error with a bit of additional context. This will allow functions that return io::Error can use glob with ? directly which incurs (basically) no performance issues.
Secondary point: I prefer the format "{err} while reading {path}". This is the format that path_abs uses. If you were okay with it I would like to change it, but it really isn't important.
Also, any opinion about that format would be appreciated... I could still improve it!
I would like to have this feature too. Can I implement it myself and open a pull request? This issue seems to have become stale
Orphan rules won't allow us to add impl From<glob::Error> for io::Error in this crate. We could add the Into impl, but that wouldn't work with ? as far as I know.
@mendess have you seen #66 which adds into_error? Is that sufficient for you?