Summary
convert_avro_schema_to_rust(..., avro_annotation=True, serde_annotation=True) produces a Rust data crate that fails to compile for real-world multi-type schemas that include enums/unions. The Serde-only output (avro_annotation=False) compiles and works correctly; only the Avro-annotation path is affected.
This blocks enabling Avro binary encoding for Rust in the xRegistry code generator (xregistry/codegen#542); we currently have to force avro_annotation=False for Rust as a workaround.
Version
- avrotize 3.8.0
- rustc / cargo 1.92.0 (stable), edition 2021
Reproduction
Generate a Rust data crate with Avro annotations from a schema set that contains enums/unions (the xRegistry lightbulb.xreg.json sample reproduces it), then cargo build:
from avrotize import convert_avro_schema_to_rust
# schema list containing records + enums/unions
convert_avro_schema_to_rust(schema, out_dir, package_name="demodata",
serde_annotation=True, avro_annotation=True)
Observed errors
error: implementation is not supported in `trait`s or `impl`s
= note: this error originates in the macro `__lazy_static_internal`
which comes from the expansion of the macro `lazy_static`
error[E0412]: cannot find type `SCHEMA` in this scope
error[E0422]: cannot find struct, variant or union type `SCHEMA` in this scope
The lazy_static! { pub static ref SCHEMA: Schema = ... } block appears to be emitted inside an impl/trait block (and/or references to SCHEMA are generated in scopes where the lazy_static-defined SCHEMA is not in scope) for enum/union types. A lazy_static! invocation is only valid at module scope, not inside impl/trait items.
For a single simple record the block is correctly emitted at module scope and compiles; the failure appears specific to enum/union type emission and/or multi-type crates.
Expected
The Avro-annotated Rust output compiles for enums, unions, and multi-type crates, with SCHEMA defined at module scope (or the Avro schema constant provided in a form valid inside impl blocks, e.g. a const/function instead of lazy_static!).
Impact / workaround
The xRegistry generator now passes avro_annotation=False for Rust so generated data crates always compile (Serde/JSON path). We'd like to re-enable Avro binary encoding for Rust once this is fixed.
Summary
convert_avro_schema_to_rust(..., avro_annotation=True, serde_annotation=True)produces a Rust data crate that fails to compile for real-world multi-type schemas that include enums/unions. The Serde-only output (avro_annotation=False) compiles and works correctly; only the Avro-annotation path is affected.This blocks enabling Avro binary encoding for Rust in the xRegistry code generator (xregistry/codegen#542); we currently have to force
avro_annotation=Falsefor Rust as a workaround.Version
Reproduction
Generate a Rust data crate with Avro annotations from a schema set that contains enums/unions (the xRegistry
lightbulb.xreg.jsonsample reproduces it), thencargo build:Observed errors
The
lazy_static! { pub static ref SCHEMA: Schema = ... }block appears to be emitted inside animpl/traitblock (and/or references toSCHEMAare generated in scopes where thelazy_static-definedSCHEMAis not in scope) for enum/union types. Alazy_static!invocation is only valid at module scope, not insideimpl/traititems.For a single simple record the block is correctly emitted at module scope and compiles; the failure appears specific to enum/union type emission and/or multi-type crates.
Expected
The Avro-annotated Rust output compiles for enums, unions, and multi-type crates, with
SCHEMAdefined at module scope (or the Avro schema constant provided in a form valid insideimplblocks, e.g. aconst/function instead oflazy_static!).Impact / workaround
The xRegistry generator now passes
avro_annotation=Falsefor Rust so generated data crates always compile (Serde/JSON path). We'd like to re-enable Avro binary encoding for Rust once this is fixed.