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
|
use snafu::prelude::*;
#[derive(Debug, Snafu)]
enum Error {
/// No user available.
/// You may need to specify one.
///
/// Here is a more detailed description.
MissingUser,
/// This is just a doc comment.
#[snafu(display("This is {}", stronger))]
Stronger { stronger: &'static str },
#[doc(hidden)]
Hidden,
}
#[cfg(feature="std")]
#[test]
fn implements_error() {
fn check<T: std::error::Error>() {}
check::<Error>();
}
#[test]
fn uses_doc_comment() {
assert_eq!(
Error::MissingUser.to_string(),
"No user available. You may need to specify one.",
);
}
#[test]
fn display_is_stronger_than_doc_comment() {
assert_eq!(
Error::Stronger {
stronger: "always stronger!"
}
.to_string(),
"This is always stronger!",
);
}
|