sapling/failure_ext
Jeremy Fitzhardinge b44055a6b3 rust/failure_ext: add err_downcast/err_downcast_ref macros
Summary:
Add a pair of macros to make downcasting errors less tedious:
```
let res = err_downcast! {
    err, // failure::Error
    foo: FooError => { println!("err is an FooError! {:?}", foo) },
    bar: BarError => { println!("err is a BarError! {:?}", bar) },
};
```

`err_downcast` takes `failure::Error` and deconstructs it into one of the
desired types and returns `Ok(match action)`, or returning it as `Err(Error)`
if nothing matches.

`err_downcast_ref` takes `&failure::Error` and gives a reference type. It
returns `Some(match action)` or `None` if nothing matches.

The error types are required to implement `failure::Fail`.

`err_downcast_ref` also matches each error type `E` as `Context<E>`.

Reviewed By: lukaspiatkowski

Differential Revision: D9394193

fbshipit-source-id: c56d91362d5bed8ab3e254bc44bb6f8a0eb376a2
2018-09-06 14:24:06 -07:00
..
src rust/failure_ext: add err_downcast/err_downcast_ref macros 2018-09-06 14:24:06 -07:00
Cargo.toml tp2/rust: rust-crates-io update 2018-08-02 10:06:47 -07:00