Expand description
§#[derive(RFactor)] - Enum ↔ R Factor Support
This module implements the #[derive(RFactor)] macro which generates
the RFactor trait implementation for C-style enums, enabling automatic
conversion between Rust enums and R factors.
§Usage
ⓘ
#[derive(Copy, Clone, RFactor)]
enum Color {
Red,
Green,
Blue,
}
// Generates impl RFactor for Color, IntoR for Color, TryFromSexp for Color,
// and Vec/Option variants.§Attributes
#[r_factor(rename = "name")]- Rename a variant’s level string#[r_factor(rename_all = "snake_case")]- Rename all variants (snake_case, kebab-case, lower, upper)
ⓘ
#[derive(Copy, Clone, RFactor)]
#[r_factor(rename_all = "snake_case")]
enum Status {
InProgress, // level: "in_progress"
#[r_factor(rename = "done")]
Completed, // level: "done"
}§Interaction Factors
For enums wrapping another RFactor type (like R’s interaction()):
ⓘ
#[derive(Copy, Clone, RFactor)]
enum Supplement { OJ, VC }
#[derive(Copy, Clone, RFactor)]
#[r_factor(interaction = ["OJ", "VC"])] // inner type's levels
enum SpeciesSupplement {
Setosa(Supplement),
Versicolor(Supplement),
Virginica(Supplement),
}
// Levels: ["Setosa.OJ", "Setosa.VC", "Versicolor.OJ", ...]Structs§
- RFactor
Attrs 🔒 - Parsed
#[r_factor(...)]attributes from an enum or variant.
Functions§
- derive_
interaction_ 🔒factor - Generate
RFactor,MatchArg,IntoR, andTryFromSexpimpls for interaction (tuple variant) enums. - derive_
r_ factor - Main entry point for
#[derive(RFactor)]. - derive_
simple_ 🔒factor - Generate
RFactor,MatchArg,IntoR, andTryFromSexpimpls for simple (unit variant) enums. - parse_
r_ 🔒factor_ attrs - Parse
#[r_factor(...)]attributes from a list ofsyn::Attribute.