Module validator

Module validator 

Source
Expand description

§Custom name validation

By default, the library follows the rules specified in the Avro specification.

Some of the other Apache Avro language SDKs are more flexible in their name validation. For interoperability with those SDKs, the library provides a way to customize the name validation.

use apache_avro::AvroResult;
use apache_avro::schema::Namespace;
use apache_avro::validator::{SchemaNameValidator, set_schema_name_validator};

struct MyCustomValidator;

impl SchemaNameValidator for MyCustomValidator {
    fn validate(&self, name: &str) -> AvroResult<(String, Namespace)> {
        todo!()
    }
}

// don't parse any schema before registering the custom validator(s)!

if set_schema_name_validator(Box::new(MyCustomValidator)).is_err() {
    // `.unwrap()` doesn't work as the return type does not implement `Debug`
    panic!("There was already a schema validator configured")
}

// ... use the library

Similar logic could be applied to the schema namespace, enum symbols and field names validation.

Note: the library allows to set a validator only once per the application lifetime! If the application parses schemas before setting a validator, the default validator will be registered and used!

Traits§

EnumSymbolNameValidator
A trait that validates enum symbol names.
RecordFieldNameValidator
A trait that validates record field names.
SchemaNameValidator
A trait that validates schema names.
SchemaNamespaceValidator
A trait that validates schema namespaces.

Functions§

set_enum_symbol_name_validator
Sets a custom enum symbol name validator.
set_record_field_name_validator
Sets a custom record field name validator.
set_schema_name_validator
Sets a custom schema name validator.
set_schema_namespace_validator
Sets a custom schema namespace validator.