File: error_as_cause.rs

package info (click to toggle)
rust-failure 0.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 364 kB
  • sloc: sh: 37; makefile: 17
file content (18 lines) | stat: -rw-r--r-- 400 bytes parent folder | download | duplicates (23)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#[macro_use]
extern crate failure;

use failure::{err_msg, Error, Fail};

#[derive(Debug, Fail)]
#[fail(display = "my wrapping error")]
struct WrappingError(#[fail(cause)] Error);

fn bad_function() -> Result<(), WrappingError> {
    Err(WrappingError(err_msg("this went bad")))
}

fn main() {
    for cause in Fail::iter_causes(&bad_function().unwrap_err()) {
        println!("{}", cause);
    }
}