Matching ErrorKind from boxed Error

There is a function returning some Result<foo, Box<Error>>. I want to recover from some of these errors, i.e. from std::io::Error with ErrorKind::TimedOut. I created an Example in the playground for this.

In short: I want this kind of match (or equivalent) to work with a boxed error:

    match whatever {
      Ok(_) => println!("Yay, OK!"),
      // Err(ref e) if e.kind() == std::io::ErrorKind::TimedOut => println!("Oh noes, timeout!"),
      Err(e) => println!("Unknown error: {:?}", e),
    };

dyn Error exposes methods that allow you to check the boxed type and downcast it: https://doc.rust-lang.org/std/error/trait.Error.html#methods

1 Like

Nice! So this is the way to go?

It works, but maybe I'm missing some sugar?