schema_registry_client/
lib.rs

1//!A fully asynchronous Rust client library for interacting with the
2//![Confluent Schema Registry](https://github.com/confluentinc/schema-registry).
3//!
4//!# The library
5//!
6//!`rust-schema-registry-client` provides a Schema Registry client, along with serdes (serializers/deserializers) for
7//!Avro, Protobuf, and JSON Schema.
8//!
9//!
10//!## Features
11//!
12//!- Support for Avro, Protobuf, and JSON Schema formats
13//!- Data quality rules using Google Common Expression Language (CEL) expressions
14//!- Schema migration rules using JSONata expressions
15//!- Client-side field-level encryption (CSFLE) rules using AWS KMS, Azure Key Vault, Google Cloud KMS, or HashiCorp Vault
16//!
17//!This library can be used with [rust-rdkafka](https://github.com/fede1024/rust-rdkafka) but does not depend on it.
18//!
19//!## Serdes
20//!
21//!- [`AvroSerializer`] and [`AvroDeserializer`] - serdes that use `apache-avro`
22//!- [`ProtobufSerializer`] and [`ProtobufDeserializer`] - serdes that use `prost` and `prost-reflect`
23//!- [`JsonSerializer`] and [`JsonDeserializer`] - serdes that use `jsonschema`
24//!
25//!# Installation
26//!
27//!Add this to your `Cargo.toml`:
28//!
29//!```toml
30//![dependencies]
31//!schema-registry-client = { version = "0.4.1" }
32//!```
33//!
34//!The following features are available:
35//!
36//!- `rules-cel` - enables data quality rules using CEL
37//!- `rules-encryption-awskms` - enables CSFLE rules using AWS KMS
38//!- `rules-encryption-azurekms` - enables CSFLE rules using Azure Key Vault
39//!- `rules-encryption-gcpkms` - enables CSFLE rules using Google Cloud KMS
40//!- `rules-encryption-hcvault` - enables CSFLE rules using HashiCorp Vault
41//!- `rules-encryption-localkms` - enables CSFLE rules using a local KMS (for testing)
42//!- `rules-jsonata` - enables schema migration rules using JSONata
43//!
44//!For example, to use CSFLE with the AWS KMS, add this to your `Cargo.toml`:
45//!
46//!```toml
47//!
48//![dependencies]
49//!schema-registry-client = { version = "0.4.0", features = ["rules-encryption-awskms"] }
50//!```
51//!
52//!# Examples
53//!
54//!You can find examples in the [`examples`] folder. To run them:
55//!
56//!```bash
57//!cargo run --example <example_name> -- <example_args>
58//!```
59//!
60//!Further information can be found in this [blog](https://yokota.blog/2025/04/16/using-data-contracts-with-the-rust-schema-registry-client/).
61//!
62//![`AvroSerializer`]: https://docs.rs/schema-registry-client/*/schema_registry_client/serdes/avro/struct.AvroSerializer.html
63//![`AvroDeserializer`]: https://docs.rs/schema-registry-client/*/schema_registry_client/serdes/avro/struct.AvroDeserializer.html
64//![`ProtobufSerializer`]: https://docs.rs/schema-registry-client/*/schema_registry_client/serdes/protobuf/struct.ProtobufSerializer.html
65//![`ProtobufDeserializer`]: https://docs.rs/schema-registry-client/*/schema_registry_client/serdes/protobuf/struct.ProtobufDeserializer.html
66//![`JsonSerializer`]: https://docs.rs/schema-registry-client/*/schema_registry_client/serdes/json/struct.JsonSerializer.html
67//![`JsonDeserializer`]: https://docs.rs/schema-registry-client/*/schema_registry_client/serdes/json/struct.JsonDeserializer.html
68//![`examples`]: https://github.com/rayokota/rust-schema-registry-client/blob/master/examples/
69
70use prost_reflect::DescriptorPool;
71use std::sync::LazyLock;
72
73pub mod rest;
74pub mod rules;
75pub mod serdes;
76
77static FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("codegen/file_descriptor_set.bin");
78
79static DESCRIPTOR_POOL: LazyLock<DescriptorPool> = LazyLock::new(|| {
80    // Get a copy of the global descriptor pool with the Google well-known types.
81    let mut pool = DescriptorPool::global();
82    pool.decode_file_descriptor_set(FILE_DESCRIPTOR_SET)
83        .expect("Failed to load file descriptor set");
84    pool
85});
86
87static TEST_FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("codegen/test/file_descriptor_set.bin");
88
89static TEST_DESCRIPTOR_POOL: LazyLock<DescriptorPool> = LazyLock::new(|| {
90    // Get a copy of the global descriptor pool with the Google well-known types.
91    let mut pool = DescriptorPool::global();
92    pool.decode_file_descriptor_set(TEST_FILE_DESCRIPTOR_SET)
93        .expect("Failed to load file descriptor set");
94    pool
95});