macro_rules! ensure {
    ($cond:expr) => {
        if !($cond) {
            return Err(Default::default());
        }
    };
}

#[derive(Debug)]
pub struct EnsureError {
    pub condition: &'static str,
    pub file: &'static str,
    pub line: u32,
}

impl std::fmt::Display for EnsureError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Condition failed: `{}` at {}:{}", self.condition, self.file, self.line)
    }
}


macro_rules! ensure {
    ($cond:expr) => {
        if !($cond) {
            let err = EnsureError {
                condition: stringify!($cond),
                file: file!(),
                line: line!(),
            };
            return Err(err.into());
        }
    };
}


#[derive(thiserror::Error, Debug)]
pub enum MyLibError {
    #[error("Validation error: {0}")]
    ValidationError(#[from] EnsureError),

    // You can still have other specific errors
    #[error("IO failure")]
    Io(#[from] std::io::Error),
}
