Expand description
§Mapping the Avro data model to the Serde data model
When manually mapping an Avro schema to Rust types it is important to understand how the different data models are mapped. When mapping from Rust types to an Avro schema, see the documentation for the reverse.
Only the mapping as defined here is supported. Any other behavior might change in a minor version.
§Primitive Types
null:()boolean:boolint:i32(ori16,i8,u16,u8)long:i64(oru32)float:f32double:f64bytes:Vec<u8>(or any type that usesSerializer::serialize_bytes,Deserializer::deserialize_bytes,Deserializer::deserialize_byte_buf)- It is required to use
apache_avro::serde::bytesas otherwise Serde will (de)serialize aVecas an array of integers instead.
- It is required to use
string:String(or any type that usesSerializer::serialize_str,Deserializer::deserialize_str,Deserializer::deserialize_string)
§Complex Types
records: A struct with the same name and fields or a tuple with the same fields.- Extra fields can be added to the struct if they are marked with
#[serde(skip)]
- Extra fields can be added to the struct if they are marked with
enums: A enum with the same name and unit variants for every symbol- The index of the symbol must match the index of the variant
arrays:Vec(or any type that usesSerializer::serialize_seq,Deserializer::deserialize_seq)[T; N]is (de)serialized as a tuple by Serde, to (de)serialize them as anarrayuseapache_avro::serde::array
maps:HashMap<String, _>(or any type that usesSerializer::serialize_map,Deserializer::deserialize_map)unions: An enum with a variant for each union variant- The index of the union variant must match the enum variant
- A
nullcan be a unit variant or a newtype variant with a unit type - All other variants must be newtype variants, struct variants, or tuple variants.
fixed:Vec<u8>(or any type that usesSerializer::serialize_bytes,Deserializer::deserialize_bytes,Deserializer::deserialize_byte_buf)- It is required to use
apache_avro::serde::fixedas otherwise Serde will (de)serialize aVecas an array of integers instead.
- It is required to use