Testing for ErrorKind from a Box<dyn Error>
Solution 1:
std::error::Error
doesn't have a kind
method; it's a method of std::io::Error
. If you only have access to the base trait you won't be able to call it.
If you make that Box<dyn std::error::Error>
a std::io::Error
instead you'll have access to it. (And there's no need for a boxed trait object since std::io::Error
is a concrete struct.)
Better yet, you can return a std::io::Result<_>
, which is a Result
type specialized to hold std::io::Error
s:
use std::io;
pub fn run(config: Config) -> io::Result<()> {
let contents = fs::read_to_string(config.filename)?;
// -- snip
Ok(())
}