Skip to main content

Crate avdl

Crate avdl 

Source
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 .avdl file to a single JSON value (protocol or schema). Equivalent to avro-tools idl.
  • Idl2Schemata — extract individual named schemas from a .avdl file, each as a self-contained .avsc JSON value. Equivalent to avro-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.
Idl2Schemata
Builder for extracting individual .avsc schemas from Avro IDL.
IdlOutput
Result of compiling an Avro IDL source.
NamedSchema
A single named schema extracted from an Avro IDL file.
SchemataOutput
Result of extracting individual schemas from Avro IDL.