10 releases
Uses new Rust 2024
| 0.3.3 | May 18, 2026 |
|---|---|
| 0.3.2 | May 14, 2026 |
| 0.2.6 | Apr 20, 2026 |
| 0.1.0 | Mar 9, 2026 |
#4 in Programming languages
105KB
1.5K
SLoC
proto-blue-codegen
Code generator that produces Rust types from AT Protocol Lexicon JSON schemas.
This is a binary crate, not a library.
Installation
cargo install proto-blue-codegen
Usage
proto-blue-codegen --lexicons path/to/lexicons --output path/to/output
The generator reads Lexicon JSON schema files from the input directory and writes Rust source files to the output directory. The generated types include records, queries, procedures, and subscriptions defined by the AT Protocol.
Output format
- String fields with a recognised
format(did,handle,at-identifier,nsid,at-uri,tid,record-key,datetime) emit as the corresponding validated newtype fromproto_blue_syntaxrather thanString. XRPC param helpers (to_query_params,params_from_ctx) round-trip throughDisplay::to_stringand<Newtype>::new(&str)?. - Inline unions in property position emit a synthesised sum-type enum named
<TypeName><PropertyPascalCase>Refs(or…ItemRefsforArray<Union>), replacing the previousserde_json::Valuefallback. - Reserved-keyword sanitization covers Rust 2024 edition keywords (
gen,try), reserved-for-future words (abstract,become,box,do,final,macro,override,priv,typeof,unsized,virtual,yield), andunion/dyn. - Sibling-name collisions after sanitization are disambiguated with
_2/_3/... suffixes and a doc comment recording the collision, instead of silently emitting invalid Rust. - An NSID that is both a leaf and a parent (e.g.
com.example.fooandcom.example.foo.bar) writes leaf content into<path>/mod.rswith the childpub moddeclarations appended, fixing a previous E0761 ambiguous-module-file error. - NSID segments containing dashes emit
#[path = "<orig>/mod.rs"] pub mod <snake>;so the on-disk path and the Rust identifier agree. - Multi-line lexicon descriptions get
///continuation per line.
Tests
The crate ships two opt-in tests for catching second-order regressions
against a real-world Lexicon corpus. Drop a checkout of the wider
ecosystem's lexicons into lexicons.wild/ at the workspace root to enable
them:
generate_types_from_wild_corpusruns the codegen against the corpus and asserts no panics plus structural sanity.wild_corpus_compiles(#[ignore]by default) synthesises a side workspace crate from the generated output and runscargo buildagainst it, catching errors that only surface at rustc time.
License
Licensed under MIT OR Apache-2.0.
Part of the proto-blue AT Protocol SDK for Rust.
Dependencies
~14–21MB
~280K SLoC