thiserror-nostd-notrait/tests/test_error.rs

57 lines
1.0 KiB
Rust
Raw Normal View History

2019-10-09 07:41:33 -07:00
#![allow(dead_code)]
2019-10-09 07:21:57 -07:00
use std::fmt::{self, Display};
2019-10-09 07:26:23 -07:00
use std::io;
2019-10-09 07:21:57 -07:00
use thiserror::Error;
2019-10-09 07:23:58 -07:00
macro_rules! unimplemented_display {
($ty:ty) => {
impl Display for $ty {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
};
}
2019-10-09 07:21:57 -07:00
#[derive(Error, Debug)]
struct BracedError {
msg: String,
pos: usize,
}
#[derive(Error, Debug)]
struct TupleError(String, usize);
#[derive(Error, Debug)]
struct UnitError;
2019-10-09 07:26:23 -07:00
#[derive(Error, Debug)]
struct WithSource {
#[source]
cause: io::Error,
}
#[derive(Error, Debug)]
struct WithAnyhow {
#[source]
cause: anyhow::Error,
}
2019-10-09 07:41:33 -07:00
#[derive(Error, Debug)]
enum EnumError {
Braced {
#[source]
cause: io::Error,
},
Tuple(#[source] io::Error),
Unit,
}
2019-10-09 07:23:58 -07:00
unimplemented_display!(BracedError);
unimplemented_display!(TupleError);
unimplemented_display!(UnitError);
2019-10-09 07:26:23 -07:00
unimplemented_display!(WithSource);
unimplemented_display!(WithAnyhow);
2019-10-09 07:41:33 -07:00
unimplemented_display!(EnumError);