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 librarySimilar 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§
- Enum
Symbol Name Validator - A trait that validates enum symbol names.
- Record
Field Name Validator - A trait that validates record field names.
- Schema
Name Validator - A trait that validates schema names.
- Schema
Namespace Validator - 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.