File: no_context.rs

package info (click to toggle)
rust-snafu 0.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 724 kB
  • sloc: sh: 15; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 790 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use snafu::prelude::*;

#[derive(Debug, Snafu)]
struct InnerError;

fn inner() -> Result<(), InnerError> {
    Ok(())
}

#[derive(Debug, Snafu)]
#[snafu(context(false))]
struct OuterError {
    source: InnerError,
}

#[test]
fn does_not_need_context_method() {
    fn exercise() -> Result<(), OuterError> {
        inner()?;
        Ok(())
    }

    let _ = exercise();
}

mod with_source_transformation {
    use super::*;

    #[derive(Debug, Snafu)]
    #[snafu(context(false))]
    struct OuterError {
        #[snafu(source(from(InnerError, Box::new)))]
        source: Box<InnerError>,
    }

    #[test]
    fn does_not_need_context_method() {
        fn exercise() -> Result<(), OuterError> {
            inner()?;
            Ok(())
        }

        let _ = exercise();
    }
}