atrg-codegen
Lexicon-driven Rust code generation for AT Protocol applications.
Part of at-rust-go (atrg) — a batteries-included AT Protocol backend framework for Rust.
What this crate provides
This crate takes AT Protocol lexicon JSON files and generates typed Rust code. It ships zero lexicon files — only the generator tooling.
generate(input_dir, output_dir, opts)— walks a directory of.jsonlexicon files and emits Rust source to the output directoryGenOptions— controls what gets generated (handler stubs, route wiring)GenReport— summary of a generation run (files processed, types/stubs generated, output paths)
Generated output includes
- Strongly-typed
serde-derived structs for records, objects, params, and outputs - Axum handler stubs with correct input/output types returning
Result<Json<Output>, XrpcError> - A
xrpc_routes()function wiring all generated handlers into an Axum router - AT-URI helper functions for each record type
Usage
[]
= "0.1"
use Path;
use ;
Skipping handler stubs
If you only want type definitions without Axum route stubs:
let opts = GenOptions ;
let report = generate?;
CLI usage
The atrg CLI wraps this crate:
This writes generated code to src/generated/ by default.
How it works
- Walks
input_dirfor*.jsonfiles - Parses each file as an AT Protocol lexicon via
atproto-lexicon - Generates Rust types for every
record,object,query, andproceduredefinition - Optionally generates Axum handler stubs and a route-wiring function
- Writes formatted Rust source files to
output_dir
Generated code lives in your project — atrg's published crates never embed any specific lexicon's output.
License
LGPL-3.0-only — see LICENSE.