| Crates.io | polars_structpath |
| lib.rs | polars_structpath |
| version | 0.2.1 |
| created_at | 2025-12-20 08:18:36.033176+00 |
| updated_at | 2025-12-20 23:27:33.206012+00 |
| description | A library for dynamically accessing nested Rust structures using path notation |
| homepage | |
| repository | https://github.com/jmunar/polarspath |
| max_upload_size | |
| id | 1996184 |
| size | 69,548 |
The main user-facing library for dynamically accessing nested Rust structures using path notation, with seamless integration to Polars DataFrames.
polars_structpath is the primary entry point for the polars_structpath ecosystem. It provides:
"parent.name" or "parents[0].age"AnyValue and DataType typesStructPath and EnumPath traitsThis crate wraps and re-exports functionality from:
polars_structpath_types: Core types and traitspolars_structpath_derive: Derive macro implementations (optional, enabled via derive feature)Add to your Cargo.toml:
[dependencies]
polars_structpath = { version = "*", features = ["derive"] }
Then use it in your code:
use polars_core::prelude::{AnyValue, DataType};
use polars_structpath::StructPath;
#[derive(StructPath, Debug, Clone)]
struct Parent {
name: String,
age: i64,
}
#[derive(StructPath, Debug, Clone)]
struct User {
name: String,
age: i64,
#[type_hint("struct")]
parents: Vec<Parent>,
}
fn main() {
let user = User {
name: "John".to_string(),
age: 32,
parents: vec![Parent {
name: "Joseph".to_string(),
age: 65,
}],
};
// Access nested values using path notation
let father_name = user.get_value("parents[0].name").unwrap();
assert_eq!(father_name, AnyValue::String("Joseph"));
// Get type information
let name_type = User::get_type("name").unwrap().polars;
assert_eq!(name_type, DataType::String);
}
Paths support the following syntax:
"name""parent.name""parents[0]""parents[0].name"derive (default): Enables the StructPath and EnumPath derive macrosstd (default): Standard library supportThe library supports:
String, i32, i64, f64, boolStructPath traitOption<T> for all types aboveVec<T> for all supported typesEnumPath trait