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
|
#[macro_use]
extern crate failure;
use std::fmt::Debug;
use failure::Fail;
#[derive(Debug, Fail)]
#[fail(display = "An error has occurred.")]
pub struct UnboundedGenericTupleError<T: 'static + Debug + Send + Sync>(T);
#[test]
fn unbounded_generic_tuple_error() {
let s = format!("{}", UnboundedGenericTupleError(()));
assert_eq!(&s[..], "An error has occurred.");
}
#[derive(Debug, Fail)]
#[fail(display = "An error has occurred: {}", _0)]
pub struct FailBoundsGenericTupleError<T: Fail>(T);
#[test]
fn fail_bounds_generic_tuple_error() {
let error = FailBoundsGenericTupleError(UnboundedGenericTupleError(()));
let s = format!("{}", error);
assert_eq!(&s[..], "An error has occurred: An error has occurred.");
}
pub trait NoDisplay: 'static + Debug + Send + Sync {}
impl NoDisplay for &'static str {}
#[derive(Debug, Fail)]
#[fail(display = "An error has occurred: {:?}", _0)]
pub struct CustomBoundsGenericTupleError<T: NoDisplay>(T);
#[test]
fn custom_bounds_generic_tuple_error() {
let error = CustomBoundsGenericTupleError("more details unavailable.");
let s = format!("{}", error);
assert_eq!(
&s[..],
"An error has occurred: \"more details unavailable.\""
);
}
|