Skip to main content

gam_models/
macros.rs

1//! Declarative `return Err(...)` shorthands for the repetitive `bail_*`
2//! patterns whose error types live in **this** crate (`gam-models`).
3//!
4//! The shared `impl_reason_error_boilerplate!` derive used by every
5//! `{ reason: String }`-shaped error enum was carved down into the base kernel
6//! crate (`gam-model-kernels`) under #1521; it is brought back into crate-wide
7//! textual scope via `#[macro_use] extern crate gam_model_kernels;` at the crate
8//! root so the unqualified call sites here resolve unchanged.
9//!
10//! The `bail_*` shorthands for error types that were relocated to the neutral
11//! `gam-problem` crate (`bail_invalid_estim!`, `bail_dim_custom!`) are *not*
12//! redefined here — they are re-exported from `gam-problem` at the crate root so
13//! `crate::bail_invalid_estim!` / `crate::bail_dim_custom!` continue to resolve.
14//!
15//! Naming: `bail_<variant>_<type-shortcode>!`. Type shortcodes:
16//!   tnorm   → TransformationNormalError
17//!   surv    → SurvivalError
18//!   sls     → SurvivalLocationScaleError
19
20#[macro_export]
21macro_rules! bail_invalid_tnorm {
22    ($fmt:literal $(, $($arg:tt)*)?) => {
23        return Err($crate::transformation_normal::TransformationNormalError::InvalidInput { reason: format!($fmt $(, $($arg)*)?) })
24    };
25    ($msg:expr $(,)?) => {
26        return Err($crate::transformation_normal::TransformationNormalError::InvalidInput { reason: $msg })
27    };
28}
29
30#[macro_export]
31macro_rules! bail_invalid_surv {
32    ($fmt:literal $(, $($arg:tt)*)?) => {
33        return Err($crate::survival::SurvivalError::InvalidInput { reason: format!($fmt $(, $($arg)*)?) })
34    };
35    ($msg:expr $(,)?) => {
36        return Err($crate::survival::SurvivalError::InvalidInput { reason: $msg })
37    };
38}
39
40#[macro_export]
41macro_rules! bail_dim_sls {
42    ($fmt:literal $(, $($arg:tt)*)?) => {
43        return Err($crate::survival::location_scale::SurvivalLocationScaleError::DimensionMismatch { reason: format!($fmt $(, $($arg)*)?) })
44    };
45    ($msg:expr $(,)?) => {
46        return Err($crate::survival::location_scale::SurvivalLocationScaleError::DimensionMismatch { reason: $msg })
47    };
48}