Expand description
Avro IDL compiler — parse .avdl files and emit Avro protocol (.avpr) or
schema (.avsc) JSON.
This crate provides two main entry points, mirroring the avro-tools CLI
subcommands:
Idl— compile a.avdlfile to a single JSON value (protocol or schema). Equivalent toavro-tools idl.Idl2Schemata— extract individual named schemas from a.avdlfile, each as a self-contained.avscJSON value. Equivalent toavro-tools idl2schemata.
Both are non-consuming builders that can be reused across multiple calls.
§Compiling a protocol
use avdl::Idl;
let output = Idl::new()
.import_dir("schemas/shared/")
.convert("schemas/service.avdl")?;
println!("{}", serde_json::to_string_pretty(&output.json)?);§Extracting individual schemas
use avdl::Idl2Schemata;
let output = Idl2Schemata::new()
.extract("schemas/service.avdl")?;
for schema in &output.schemas {
std::fs::write(
format!("{}.avsc", schema.name),
serde_json::to_string_pretty(&schema.schema)?,
)?;
}§Error handling
All fallible methods return miette::Result, which provides rich
diagnostic output with source spans when printed with {:?}.
Structs§
- Idl
- Builder for compiling Avro IDL to protocol (
.avpr) or schema (.avsc) JSON. - Idl2
Schemata - Builder for extracting individual
.avscschemas from Avro IDL. - IdlOutput
- Result of compiling an Avro IDL source.
- Named
Schema - A single named schema extracted from an Avro IDL file.
- Schemata
Output - Result of extracting individual schemas from Avro IDL.