Module schema_equality

Module schema_equality 

Source
Expand description

§Custom schema equality comparators

The library provides two implementations of schema equality comparators:

  1. StructFieldEq (default) - compares the schemas structurally, may slightly deviate from the specification.
  2. 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 library

Note: 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§

SpecificationEq
Compares two schemas according to the Avro specification by using [their canonical forms].
StructFieldEq
Compares [the canonical forms] of two schemas for equality field by field.

Traits§

SchemataEq
A trait that compares two schemata for equality.

Functions§

set_schemata_equality_comparator
Sets a custom schemata equality comparator.