Skip to main content

derive_interaction_factor

Function derive_interaction_factor 

Source
fn derive_interaction_factor(
    name: &Ident,
    impl_generics: &ImplGenerics<'_>,
    ty_generics: &TypeGenerics<'_>,
    where_clause: Option<&WhereClause>,
    variants: &Punctuated<Variant, Comma>,
    inner_levels: &[String],
    sep: &str,
    rename_all: Option<&str>,
) -> Result<TokenStream>
Expand description

Generate RFactor, MatchArg, IntoR, and TryFromSexp impls for interaction (tuple variant) enums.

Interaction factors combine an outer enum (the variant) with an inner RFactor type, producing combined level names like "Outer.Inner". The level order is outer-varies-slowest (matches R’s interaction(..., lex.order = TRUE)).

Generates a compile-time assertion that the specified inner_levels match the inner type’s MatchArg::CHOICES, catching mismatches early.

All variants must be single-field tuples wrapping the same inner type.

§Arguments

  • inner_levels - The expected level strings of the inner type (from #[r_factor(interaction = [...])])
  • sep - Separator between outer and inner level names (default ".")
  • rename_all - Optional rename transformation for outer variant names