Skip to main content

Module condition_derive

Module condition_derive 

Source
Expand description

Code generation for #[derive(RCondition)].

Generates impl miniextendr_api::condition::RConditionData from the type’s structure, and From<T> for miniextendr_api::condition::RCondition, so a package keeps one Rust type per condition family and gets the R side without hand-written glue:

  • class(): c(<member>, <family>) for enum variants, c(<family>) for structs. #[condition(class("…", "…"))] on a struct is its whole class vector, and on a variant it replaces the member. The family is #[condition(class = "…")] on the type, else the type name in snake_case; the member is the same attribute on the variant, else <family>_<variant in snake_case>.

  • message(): #[condition(message = "…")] on the struct or on a variant is a format! string with the fields in scope (tuple fields as _0, _1, …). Without it the message is the type’s Display rendering.

  • data(): every field as a named entry built with RValue::from(field.clone()). #[condition(rename = "…")] changes the name, #[condition(skip)] drops the field, #[condition(debug)] attaches the Debug rendering (RValue::debug) instead of a conversion. Tuple fields need rename or skip; the condition’s own slots (message, call, kind) are rejected. #[condition(skip_none)] on an Option field leaves its entry out when it is None. #[condition(data(name = value, …))] on the type or a variant adds entries after the fields’, each RValue::from(value). With no entries, data() is None.

  • call(): #[condition(call = none)] on the type (every variant) or on one variant raises that condition without a call (conditionCall() is NULL, R’s call. = FALSE). Without it the method keeps the trait’s default, the call the transport captured.

  • argument_message(): #[condition(argument_message = "…")] on the struct or on a variant, a format! string like message. It is the whole message when the error refuses an argument in a conversion (#1833); a variant without it keeps the trait’s default, None.

  • From<T> for RCondition: the kind is #[condition(kind = …)] on the variant, else on the type, else error. Only RCondition::from(x) (.defer() / .raise()) reads it: a returned Err(x) is always an R error, and defer_warning(x) / defer_message(x) choose their own kind.

The payload feeds defer_warning & co. (a condition accompanying a value) and Result<T, E> returns (a classed error): both go through the trait. Generic types are rejected, like the other derives in this crate.

Structs§

ContainerAttrs 🔒
#[condition(...)] options on the type or on one variant.
DataEntry 🔒
One data(name = value) entry.
FieldAttrs 🔒
#[condition(...)] options on one field.
FieldInfo 🔒
One field of a struct or variant, as the derive sees it.
Shape 🔒
The fields of a struct or of one enum variant, validated, with the data(...) entries that follow them.

Enums§

ClassSpec 🔒
class = "…" or class("…", "…").
Style 🔒

Constants§

RESERVED_FIELDS 🔒
The condition object’s own slots. Mirrors miniextendr_api::condition::RESERVED_CONDITION_FIELDS; keep in sync.

Functions§

check_data_name 🔒
Refuse a name the condition object owns, or one already in seen.
condition_expr 🔒
The RCondition variant for a declared kind; no kind is an error.
derive_condition 🔒
derive_r_condition
Main entry point for #[derive(RCondition)]: the RConditionData metadata and From<T> for RCondition with the declared kind.
is_option 🔒
Whether ty is written as Option<_> (any path ending in Option).
parse_container_attrs 🔒
parse_field_attrs 🔒