#struct #path #json

macro struct-path

A helper macros to build a string that represents struct fields path at compile time (such as <field-name>.<field-name>)

6 releases

Uses new Rust 2021

0.2.2 Oct 23, 2022
0.2.0 Oct 23, 2022
0.1.4 Oct 22, 2022

#516 in Rust patterns

Download history 278/week @ 2022-10-20 91/week @ 2022-10-27 327/week @ 2022-11-03 446/week @ 2022-11-10 305/week @ 2022-11-17 126/week @ 2022-11-24

1,237 downloads per month
Used in firestore


405 lines

Cargo tests and formatting security audit

struct-path for Rust

Library provides a tiny macro implementation to reference Rust struct fields at compile time to represent its string format. This is needed to work with JSON paths, and some others protocols when we still want to rely on the compiler to avoid inconsistent changes.


  • Fast and no macro parsing without huge deps;
  • Macro produces the code to verify if the specified path really exists;
  • Multiple fields/arrays support
  • Optional camelCase and PascalCase conversion support;
  • Optional delimiter parameter;

Quick start


struct-path = "0.2"

Example code:

use struct_path::*;

pub struct TestStructParent {
    pub value_str: String,
    pub value_num: u64,
    pub value_child: TestStructChild,

pub struct TestStructChild {
    pub child_value_str: String,
    pub child_value_num: u64,

// returns "value_str"
let s1: &str = path!(TestStructParent::value_str);

// returns "value_child.child_value_str"
let s2: &str = path!(TestStructParent::value_child.child_value_str) ;

// returns also "value_child.child_value_str"
let s3: &str = path!(TestStructParent::value_child,TestStructChild::child_value_str);

// options, returns "valueChild/childValueStr"
let s4: &str = path!(TestStructParent::value_child.child_value_str; delim="/", case="camel") ;

// returns ["value_str", "value_num"]
let arr: [&str; 2] = paths!(TestStructParent::{ value_str, value_num });


Apache Software License (ASL)


Abdulla Abdurakhmanov