krabka_protocol_codegen/lib.rs
1//! Build-time code generator for the `krabka-protocol` crate.
2//!
3//! The generator reads the vendored Apache Kafka JSON message schemas,
4//! validates the subset Krabka supports, resolves nested and common structs,
5//! and emits the owned and borrowed Rust protocol modules.
6//! `tools/regenerate.sh` drives the binary wrapper and writes the committed
7//! tree under `crates/protocol/generated`. The library API is useful for tests
8//! and for one-off schema audits.
9//!
10//! ## Loading and validating schemas
11//!
12//! ```no_run
13//! use std::path::Path;
14//!
15//! use krabka_protocol_codegen::{ir, validate};
16//!
17//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
18//! let specs = ir::load_dir(Path::new("crates/protocol/schemas"))?;
19//! validate::validate(&specs)?;
20//! println!("loaded {} protocol schemas", specs.len());
21//! # Ok(())
22//! # }
23//! ```
24//!
25//! ## Resolving generated type paths
26//!
27//! ```no_run
28//! use std::path::Path;
29//!
30//! use krabka_protocol_codegen::{ir, resolve};
31//!
32//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
33//! let specs = ir::load_dir(Path::new("crates/protocol/schemas"))?;
34//! let metadata = specs.iter().find(|s| s.name == "MetadataRequest").unwrap();
35//! let resolution = resolve::resolve_message(metadata)?;
36//! println!("{} referenced struct types", resolution.len());
37//! # Ok(())
38//! # }
39//! ```
40pub mod driver;
41pub mod emit;
42pub mod fmt;
43pub mod hoist;
44pub mod ir;
45pub mod name_conv;
46pub mod out;
47pub mod resolve;
48pub mod type_map;
49pub mod validate;