Skip to main content

RCondition

Derive Macro RCondition 

Source
#[derive(RCondition)]
{
    // Attributes available to this derive:
    #[condition]
}
Expand description

#[derive(RCondition)]: RConditionData generated from a type’s shape (#[condition(class = "…")], #[condition(message = "…")], the rename / skip / debug field options) and From<T> for RCondition with the declared kind (#[condition(kind = …)], default error). Derive an R condition type for a struct or enum: RConditionData (the R class vector, the message and the data fields handlers read as e$<name>) and From<Self> for miniextendr_api::RCondition.

  • #[condition(class = "…")] on the type sets the family class (default: the type name in snake_case); on an enum variant it sets the member class (default: <family>_<variant in snake_case>). Variants report c(<member>, <family>), structs c(<family>).
  • #[condition(message = "…")] on a struct or a variant is a format! string over the fields (tuple fields are _0, _1, …). Without it the message is the type’s Display rendering.
  • Every field becomes a data entry under its own name, converted with RValue::from(field.clone()), so its type must be Clone. #[condition(rename = "…")], #[condition(skip)] and #[condition(debug)] (attach the Debug rendering instead) adjust that; tuple fields need rename or skip. The reserved slots message, call and kind are rejected at compile time.
  • #[condition(kind = error | warning | message | condition)] on the type or a variant (the variant wins) is the kind RCondition::from(value) gives it; the default is error. Then .defer() signals it after the function returns its value, and .raise() signals it now.

The kind is read only through RCondition::from. Returned as Err(value) from a Result<T, E>, the value is always an R error, and defer_warning / defer_message signal the kind they are named after. Generic types are not supported.