Skip to main content

derive_dataframe_row

Function derive_dataframe_row 

Source
pub fn derive_dataframe_row(input: DeriveInput) -> Result<TokenStream>
Expand description

Derive DataFrameRow: generates a companion DataFrame type with collection fields.

§Requirements

For structs: the type must implement IntoList. For enums: all variants must have named fields.

§Generated Items

For a struct Measurement { time: f64, value: f64 }:

  • Struct MeasurementDataFrame { time: Vec<f64>, value: Vec<f64> }
  • impl IntoDataFrame for MeasurementDataFrame (rows → R data.frame)
  • impl ColumnarFrame for MeasurementDataFrame (rows ↔ the pure-Rust companion)
  • impl From<Vec<Measurement>> for MeasurementDataFrame
  • impl IntoIterator for MeasurementDataFrame

For an enum:

  • Companion struct with Vec<Option<T>> columns (field-name union)
  • Optional tag column for variant discrimination
  • impl From<Vec<Enum>> for EnumDataFrame
  • impl IntoDataFrame for EnumDataFrame
  • impl ColumnarFrame for EnumDataFrame
  • impl DataFrameRowSplit for Enum (the split representation behind IntoDataFrameSplit)

§Public surface (which verbs to call)

  • Rows → R data.frame: rows.into_dataframe()? (/_par) or rows.wrap_data_frame(), from IntoDataFrame / AsDataFrameExt.
  • R data.frame → rows: Vec::<Row>::from_dataframe(&df)? (/_par) from FromDataFrame, or the one-call Row::try_from_dataframe(sexp) reader.
  • Rows ↔ the pure-Rust columnar companion: the ColumnarFrame trait (<Row>DataFrame::from_rows / from_rows_par / into_rows), or the std Vec<Row>: Into<companion> / companion IntoIterator.
  • Enums: rows.into_dataframe_split() (one data.frame per variant) from IntoDataFrameSplit, implemented via the hidden DataFrameRowSplit bridge on the enum type.

All the traits above are re-exported from miniextendr_api::prelude. The row type also carries two #[doc(hidden)] helpers: to_dataframe(rows) -> companion, retained only because the struct-flatten / nested-enum write paths build a nested companion via Inner::to_dataframe(..) without naming its type, and to_dataframe_split(rows), the body holder behind the DataFrameRowSplit bridge.

§Attributes

  • #[dataframe(name = "CustomName")] — Custom companion type name
  • #[dataframe(align)] — Enum alignment mode (accepted but implicit)
  • #[dataframe(tag = "col")] — Add variant discriminator column