Expand description
§Custom schema equality comparators
The library provides two implementations of schema equality comparators:
StructFieldEq(default) - compares the schemas structurally, may slightly deviate from the specification.SpecificationEq- compares the schemas by serializing them to their canonical form and comparing the resulting JSON.
To use a custom comparator, you need to implement the SchemataEq trait and set it using the
set_schemata_equality_comparator function:
use apache_avro::{AvroResult, Schema};
use apache_avro::schema::Namespace;
use apache_avro::schema_equality::{SchemataEq, set_schemata_equality_comparator};
#[derive(Debug)]
struct MyCustomSchemataEq;
impl SchemataEq for MyCustomSchemataEq {
fn compare(&self, schema_one: &Schema, schema_two: &Schema) -> bool {
todo!()
}
}
// don't parse any schema before registering the custom comparator!
set_schemata_equality_comparator(Box::new(MyCustomSchemataEq));
// ... use the libraryNote: the library allows to set a comparator only once per the application lifetime! If the application parses schemas before setting a comparator, the default comparator will be registered and used!
Structs§
- Specification
Eq - Compares two schemas according to the Avro specification by using [their canonical forms].
- Struct
Field Eq - Compares [the canonical forms] of two schemas for equality field by field.
Traits§
- Schemata
Eq - A trait that compares two schemata for equality.
Functions§
- set_
schemata_ equality_ comparator - Sets a custom schemata equality comparator.