A proc-macro module for automatically deriving the avro schema for structs or enums. The macro produces the logic necessary to implement the AvroSchema
trait for the type.
rust
pub trait AvroSchema {
// constructs the schema for the type
fn get_schema() -> Schema;
}
Add the "derive" feature to your apache-avro dependency inside cargo.toml
apache-avro = { version = "X.Y.Z", features = ["derive"] }
Add to your data model ```rust
struct Test { a: i64, b: String, } ```
```rust use apache_avro::Writer;
struct Test { a: i64, b: String, } // derived schema, always valid or code fails to compile with a descriptive message let schema = Test::get_schema();
let mut writer = Writer::new(&schema, Vec::new()); let test = Test { a: 27, b: "foo".toowned(), }; writer.appendser(test).unwrap(); let encoded = writer.into_inner(); ```
This module is designed to work in concert with the Serde implemenation. If your use case dictates needing to manually convert to a Value
type in order to encode then the derived schema may not be correct.