48 lines
1.0 KiB
Rust
48 lines
1.0 KiB
Rust
extern crate self as kaptan_log;
|
|
|
|
use kaptan_log_derive::KaptanError;
|
|
|
|
pub struct StaticErrorMessage(&'static str);
|
|
|
|
impl StaticErrorMessage {
|
|
pub const fn new(text: &'static str) -> Self {
|
|
Self(text)
|
|
}
|
|
|
|
pub const fn as_str(&self) -> &'static str {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
pub trait ErrorReport {
|
|
fn error_message(&self) -> &'static StaticErrorMessage;
|
|
}
|
|
|
|
#[derive(Debug, KaptanError)]
|
|
enum Generic<'a, T>
|
|
where
|
|
T: Copy,
|
|
{
|
|
Unit,
|
|
Tuple(T, u8),
|
|
Named { label: &'a str },
|
|
}
|
|
|
|
fn main() {
|
|
fn assert_error<T: core::error::Error>() {}
|
|
assert_error::<Generic<'_, u8>>();
|
|
assert_eq!(
|
|
Generic::<u8>::Unit.error_message().as_str(),
|
|
concat!(module_path!(), "::Generic::Unit"),
|
|
);
|
|
assert_eq!(
|
|
Generic::Tuple(1_u8, 2).error_message().as_str(),
|
|
concat!(module_path!(), "::Generic::Tuple"),
|
|
);
|
|
let named: Generic<'_, u8> = Generic::Named { label: "test" };
|
|
assert_eq!(
|
|
named.to_string(),
|
|
concat!(module_path!(), "::Generic::Named"),
|
|
);
|
|
}
|