Skip to main content

StructPath

Derive Macro StructPath 

Source
#[derive(StructPath)]
{
    // Attributes available to this derive:
    #[type_hint]
}
Expand description

Derive macro for generating Arrow buffer implementations for structs.

This macro automatically generates code that calls impl_struct_buffer! from polars-structpath, which creates:

  • A buffer struct (e.g., UserBuffer) implementing ArrowBuffer
  • IntoArrow implementation for the struct
  • FromArrow implementation for the struct

§Requirements

  • The struct must have named fields (not tuple structs or unit structs)
  • All field types must implement IntoArrow and FromArrow from polars-structpath

§Attributes

  • #[type_hint(...)]: Currently accepted but not used. Reserved for future use.

§Example

use polars_structpath::StructPath;
use polars_structpath::{IntoArrow, ArrowBuffer};

#[derive(StructPath)]
struct User {
    name: String,
    age: i64,
}

// Now User implements IntoArrow and FromArrow
let mut buffer = User::new_buffer(1);
buffer.push(User {
    name: "Alice".to_string(),
    age: 30,
});
let array = buffer.to_arrow().unwrap();