pub trait AvroSchemaComponent {
// Required method
fn get_schema_in_ctxt(
named_schemas: &mut Names,
enclosing_namespace: &Namespace,
) -> Schema;
}Expand description
Trait for types that serve as fully defined components inside an Avro data model. Derive
implementation available through derive feature. This is what is implemented by
the derive(AvroSchema) macro.
§Implementation guide
§Simple implementation
To construct a non named simple schema, it is possible to ignore the input argument making the general form implementation look like
impl AvroSchemaComponent for AType {
fn get_schema_in_ctxt(_: &mut Names, _: &Namespace) -> Schema {
Schema::?
}
}§Passthrough implementation
To construct a schema for a Type that acts as in “inner” type, such as for smart pointers, simply pass through the arguments to the inner type
impl AvroSchemaComponent for PassthroughType {
fn get_schema_in_ctxt(named_schemas: &mut Names, enclosing_namespace: &Namespace) -> Schema {
InnerType::get_schema_in_ctxt(named_schemas, enclosing_namespace)
}
}§Complex implementation
To implement this for Named schema there is a general form needed to avoid creating invalid schemas or infinite loops.
impl AvroSchemaComponent for ComplexType {
fn get_schema_in_ctxt(named_schemas: &mut Names, enclosing_namespace: &Namespace) -> Schema {
// Create the fully qualified name for your type given the enclosing namespace
let name = apache_avro::schema::Name::new("MyName")
.expect("Unable to parse schema name")
.fully_qualified_name(enclosing_namespace);
let enclosing_namespace = &name.namespace;
// Check, if your name is already defined, and if so, return a ref to that name
if named_schemas.contains_key(&name) {
apache_avro::schema::Schema::Ref{name: name.clone()}
} else {
named_schemas.insert(name.clone(), apache_avro::schema::Schema::Ref{name: name.clone()});
// YOUR SCHEMA DEFINITION HERE with the name equivalent to "MyName".
// For non-simple sub types delegate to their implementation of AvroSchemaComponent
}
}
}Required Methods§
fn get_schema_in_ctxt( named_schemas: &mut Names, enclosing_namespace: &Namespace, ) -> Schema
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl AvroSchemaComponent for bool
impl AvroSchemaComponent for bool
Source§impl AvroSchemaComponent for char
impl AvroSchemaComponent for char
Source§impl AvroSchemaComponent for f32
impl AvroSchemaComponent for f32
Source§impl AvroSchemaComponent for f64
impl AvroSchemaComponent for f64
Source§impl AvroSchemaComponent for i8
impl AvroSchemaComponent for i8
Source§impl AvroSchemaComponent for i16
impl AvroSchemaComponent for i16
Source§impl AvroSchemaComponent for i32
impl AvroSchemaComponent for i32
Source§impl AvroSchemaComponent for i64
impl AvroSchemaComponent for i64
Source§impl AvroSchemaComponent for i128
impl AvroSchemaComponent for i128
Source§fn get_schema_in_ctxt(
named_schemas: &mut Names,
enclosing_namespace: &Namespace,
) -> Schema
fn get_schema_in_ctxt( named_schemas: &mut Names, enclosing_namespace: &Namespace, ) -> Schema
The schema is Schema::Fixed of size 16 with the name i128.
Source§impl AvroSchemaComponent for str
impl AvroSchemaComponent for str
Source§impl AvroSchemaComponent for u8
impl AvroSchemaComponent for u8
Source§impl AvroSchemaComponent for u16
impl AvroSchemaComponent for u16
Source§impl AvroSchemaComponent for u32
impl AvroSchemaComponent for u32
Source§impl AvroSchemaComponent for u64
impl AvroSchemaComponent for u64
Source§fn get_schema_in_ctxt(
named_schemas: &mut Names,
enclosing_namespace: &Namespace,
) -> Schema
fn get_schema_in_ctxt( named_schemas: &mut Names, enclosing_namespace: &Namespace, ) -> Schema
The schema is Schema::Fixed of size 8 with the name u64.
Source§impl AvroSchemaComponent for u128
impl AvroSchemaComponent for u128
Source§fn get_schema_in_ctxt(
named_schemas: &mut Names,
enclosing_namespace: &Namespace,
) -> Schema
fn get_schema_in_ctxt( named_schemas: &mut Names, enclosing_namespace: &Namespace, ) -> Schema
The schema is Schema::Fixed of size 16 with the name u128.
Source§impl AvroSchemaComponent for String
impl AvroSchemaComponent for String
Source§impl AvroSchemaComponent for Duration
impl AvroSchemaComponent for Duration
Source§fn get_schema_in_ctxt(
named_schemas: &mut Names,
enclosing_namespace: &Namespace,
) -> Schema
fn get_schema_in_ctxt( named_schemas: &mut Names, enclosing_namespace: &Namespace, ) -> Schema
The schema is Schema::Duration with the name duration.
This is a lossy conversion as this Avro type does not store the amount of nanoseconds.