Skip to main content

UnitEnumFactor

Trait UnitEnumFactor 

Source
pub trait UnitEnumFactor {
    const FACTOR_LEVELS: &'static [&'static str];

    // Required method
    fn to_factor_index(self) -> i32;
}
Expand description

Trait implemented by unit-only enums derived via #[derive(DataFrameRow)].

Provides the level names and 1-based index needed to convert enum values into R factor SEXPs. Unlike RFactor, this trait does not require Copy or MatchArg, making it usable with DataFrameRow-derived types that only need to participate as factor columns in data frames.

Implemented automatically by #[derive(DataFrameRow)] on unit-only enums. The blanket impl<T: UnitEnumFactor> IntoR for FactorOptionVec<T> in miniextendr-api provides the actual SEXP conversion used by the companion struct’s into_data_frame method.

§Safety contract

to_factor_index must return a value in 1..=FACTOR_LEVELS.len() as i32 (or NA_INTEGER for missing) to produce a valid R factor SEXP.

Required Associated Constants§

Source

const FACTOR_LEVELS: &'static [&'static str]

Ordered level names (in the same order as the enum variants).

Required Methods§

Source

fn to_factor_index(self) -> i32

Convert self to a 1-based R factor level index.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: RFactor + MatchArg> UnitEnumFactor for T

Source§

const FACTOR_LEVELS: &'static [&'static str] = T::CHOICES