pub trait UnitEnumFactor: Sized {
const FACTOR_LEVELS: &'static [&'static str];
// Required methods
fn to_factor_index(self) -> i32;
fn from_factor_index(idx: i32) -> Option<Self>;
}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§
Sourceconst FACTOR_LEVELS: &'static [&'static str]
const FACTOR_LEVELS: &'static [&'static str]
Ordered level names (in the same order as the enum variants).
Required Methods§
Sourcefn to_factor_index(self) -> i32
fn to_factor_index(self) -> i32
Convert self to a 1-based R factor level index.
Sourcefn from_factor_index(idx: i32) -> Option<Self>
fn from_factor_index(idx: i32) -> Option<Self>
Inverse: 1-based level index → variant, or None if out of range.
Used by the enum DataFrame reader to reconstruct unit-only enum values
from an R factor column. The default blanket impl delegates to the
underlying RFactor::from_level_index.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".