csv-codegen 0.2.3

A Rust procedural macro that transforms CSV data into safe, zero-cost code. Generate match arms, loops, and nested queries directly from CSV files, ensuring type safety and deterministic code generation.
Documentation
use csv_codegen::csv_template;

fn main() {
    // This generates code proportional to the number of CSV rows
    // Each row becomes a separate constant, function, and match arm
    csv_template!("../../../../benchmark_data.csv", {
        #each {
            // Generate one constant per row (using unique row_id for identifier)
            pub const #CONST({row_id}_SALES): f64 = #({sales_amount}_f64);

            // Generate one function per row (using unique row_id for identifier)
            pub fn #ident(get_{row_id}_data)() -> (f64, u32) {
                (#({sales_amount}_f64), #({employee_count}_u32))
            }
        }

        // Generate a large match expression with all rows
        pub fn lookup_sales(region: &str, dept: &str, count: u32) -> Option<f64> {
            match (region, dept, count) {
                #each {
                    (#("{region}"), #("{department}"), #({employee_count}_u32)) => Some(#({sales_amount}_f64)),
                }
                _ => None,
            }
        }
    });
}