File: multiple_attributes.rs

package info (click to toggle)
rust-snafu 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 724 kB
  • sloc: sh: 15; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 895 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
use snafu::prelude::*;

#[derive(Debug, Snafu)]
enum InnerError {
    InnerVariant,
}

mod error {
    use super::InnerError;
    use snafu::prelude::*;

    #[derive(Debug, Snafu)]
    pub(super) enum Error {
        // We'll test both of these attributes inside `#[snafu(...)]`
        #[snafu(visibility(pub(super)), display("Moo"))]
        Alpha {
            // Ensure we can have multiple field attributes as well
            #[snafu(source, backtrace)]
            cause: InnerError,
        },
    }
}

// Confirm `pub(super)` is applied to the generated struct
#[test]
fn is_visible() {
    let _ = error::AlphaSnafu;
}

fn example() -> Result<u8, InnerError> {
    InnerVariantSnafu.fail()
}

// Confirm `display("Moo")` is applied to the variant
#[test]
fn has_display() {
    let err = example().context(error::AlphaSnafu).unwrap_err();
    assert_eq!(format!("{}", err), "Moo");
}