use geez::geez;
use std::error::Error;
#[derive(Debug)]
struct Inner(String);
impl std::fmt::Display for Inner {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "inner({})", self.0)
}
}
impl Error for Inner {}
geez! {
enum Chain {
#[from]
A(Inner),
#[error("context: {0}")]
Context(String),
}
}
#[test]
fn display_default_single_field() {
geez! {
enum E {
Msg(String),
}
}
assert_eq!(E::Msg("hi".into()).to_string(), "hi");
}
#[test]
fn question_mark_through_from() {
fn fail() -> Result<()> {
Err(Inner("boom".into()))?;
Ok(())
}
let err = fail().unwrap_err();
assert_eq!(err.to_string(), "inner(boom)");
assert_eq!(err.source().unwrap().to_string(), "inner(boom)");
}
#[test]
fn eight_fields() {
geez! {
enum Wide {
#[error("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}")]
All(u8, u8, u8, u8, u8, u8, u8, u8),
}
}
assert_eq!(
Wide::All(1, 2, 3, 4, 5, 6, 7, 8).to_string(),
"1-2-3-4-5-6-7-8"
);
}