Skip to main content

derive_altrep_generic

Function derive_altrep_generic 

Source
fn derive_altrep_generic(
    input: DeriveInput,
    data_trait_path: TokenStream,
    gen_elt_impl: impl FnOnce(Option<&Ident>, Option<&Ident>) -> TokenStream,
    family: &AltrepFamilyConfig<'_>,
) -> Result<TokenStream>
Expand description

Shared implementation for all non-list ALTREP derive macros.

Generates three items:

  1. impl AltrepLen – delegates to the detected/specified length field
  2. impl Alt*Data – the family-specific data trait with an elt() method
  3. Low-level trait impls via AltrepAttrs::generate_lowlevel

§Arguments

  • input – The DeriveInput from the proc-macro.
  • data_trait_path – The fully qualified path to the data trait (e.g., ::miniextendr_api::altrep_data::AltIntegerData).
  • gen_elt_impl – A closure that receives the optional elt_field and returns a token stream for the fn elt(...) method body. If elt_field is Some, the closure typically returns self.{field}; if None, it returns a family-appropriate default (NA_INTEGER, f64::NAN, 0u8, Logical::Na, None, or Rcomplex { NAN, NAN }).
  • family – The AltrepFamilyConfig for this type family.

§Errors

Returns Err if attribute parsing fails, no length field can be found, or option validation fails.