From f9ecaec6b9c02179b49655ed60d3dc3fdd14e860 Mon Sep 17 00:00:00 2001 From: gklijs Date: Sun, 13 Oct 2024 15:36:44 +0200 Subject: [PATCH] Ran a cargo format. --- src/async_impl/avro.rs | 4 ++-- src/async_impl/easy_json.rs | 2 +- src/async_impl/easy_proto_decoder.rs | 2 +- src/async_impl/easy_proto_raw.rs | 2 +- src/async_impl/json.rs | 2 +- src/async_impl/proto_decoder.rs | 2 +- src/async_impl/proto_raw.rs | 2 +- src/async_impl/schema_registry.rs | 2 +- src/avro_common.rs | 7 +------ src/schema_registry_common.rs | 26 +++++++++++++++++++++----- tests/blocking/kafka_consumer.rs | 2 +- 11 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/async_impl/avro.rs b/src/async_impl/avro.rs index bc9f86f..c3b1d6b 100644 --- a/src/async_impl/avro.rs +++ b/src/async_impl/avro.rs @@ -38,8 +38,8 @@ use crate::async_impl::schema_registry::{ get_referenced_schema, get_schema_by_id_and_type, get_schema_by_subject, SrSettings, }; use crate::avro_common::{ - get_name, item_to_bytes, replace_reference, values_to_bytes, AvroSchema, DecodeResult, record_to_bytes, - DecodeResultWithSchema, + get_name, item_to_bytes, record_to_bytes, replace_reference, values_to_bytes, AvroSchema, + DecodeResult, DecodeResultWithSchema, }; use crate::error::SRCError; use crate::schema_registry_common::{ diff --git a/src/async_impl/easy_json.rs b/src/async_impl/easy_json.rs index ea8b0b4..c66d529 100644 --- a/src/async_impl/easy_json.rs +++ b/src/async_impl/easy_json.rs @@ -46,9 +46,9 @@ mod tests { use crate::async_impl::schema_registry::SrSettings; use crate::schema_registry_common::{get_payload, SubjectNameStrategy}; + use mockito::Server; use serde_json::Value; use std::fs::{read_to_string, File}; - use mockito::Server; use test_utils::{get_json_body, json_result_java_bytes, json_result_schema}; #[tokio::test] diff --git a/src/async_impl/easy_proto_decoder.rs b/src/async_impl/easy_proto_decoder.rs index e992704..f373e3c 100644 --- a/src/async_impl/easy_proto_decoder.rs +++ b/src/async_impl/easy_proto_decoder.rs @@ -29,9 +29,9 @@ impl EasyProtoDecoder { #[cfg(test)] mod tests { - use mockito::Server; use crate::async_impl::easy_proto_decoder::EasyProtoDecoder; use crate::async_impl::schema_registry::SrSettings; + use mockito::Server; use protofish::decode::Value; use test_utils::{get_proto_body, get_proto_hb_101, get_proto_hb_schema}; diff --git a/src/async_impl/easy_proto_raw.rs b/src/async_impl/easy_proto_raw.rs index e365dd4..90d30b8 100644 --- a/src/async_impl/easy_proto_raw.rs +++ b/src/async_impl/easy_proto_raw.rs @@ -55,10 +55,10 @@ impl EasyProtoRawEncoder { #[cfg(test)] mod tests { - use mockito::Server; use crate::async_impl::easy_proto_raw::{EasyProtoRawDecoder, EasyProtoRawEncoder}; use crate::async_impl::schema_registry::SrSettings; use crate::schema_registry_common::SubjectNameStrategy; + use mockito::Server; use test_utils::{ get_proto_body, get_proto_hb_101, get_proto_hb_101_only_data, get_proto_hb_schema, diff --git a/src/async_impl/json.rs b/src/async_impl/json.rs index 56dc70c..42ffbe6 100644 --- a/src/async_impl/json.rs +++ b/src/async_impl/json.rs @@ -290,8 +290,8 @@ pub struct DecodeResult { #[cfg(test)] mod tests { - use std::fs::{read_to_string, File}; use mockito::Server; + use std::fs::{read_to_string, File}; use serde_json::Value; diff --git a/src/async_impl/proto_decoder.rs b/src/async_impl/proto_decoder.rs index aa3674c..3206599 100644 --- a/src/async_impl/proto_decoder.rs +++ b/src/async_impl/proto_decoder.rs @@ -206,9 +206,9 @@ async fn to_vec_of_schemas( #[cfg(test)] mod tests { - use mockito::Server; use crate::async_impl::proto_decoder::ProtoDecoder; use crate::async_impl::schema_registry::SrSettings; + use mockito::Server; use protofish::prelude::Value; use test_utils::{ get_proto_complex, get_proto_complex_proto_test_message, get_proto_complex_references, diff --git a/src/async_impl/proto_raw.rs b/src/async_impl/proto_raw.rs index 97800a2..f451eb1 100644 --- a/src/async_impl/proto_raw.rs +++ b/src/async_impl/proto_raw.rs @@ -220,12 +220,12 @@ pub struct RawDecodeResult { #[cfg(test)] mod tests { - use mockito::Server; use crate::async_impl::proto_raw::{ProtoRawDecoder, ProtoRawEncoder}; use crate::async_impl::schema_registry::SrSettings; use crate::schema_registry_common::{ SchemaType, SubjectNameStrategy, SuppliedReference, SuppliedSchema, }; + use mockito::Server; use test_utils::{ get_proto_body, get_proto_body_with_reference, get_proto_complex, get_proto_complex_only_data, get_proto_complex_proto_test_message, diff --git a/src/async_impl/schema_registry.rs b/src/async_impl/schema_registry.rs index 65fa938..cb93a77 100644 --- a/src/async_impl/schema_registry.rs +++ b/src/async_impl/schema_registry.rs @@ -557,8 +557,8 @@ async fn perform_single_versions_call( #[cfg(test)] mod tests { - use std::time::Duration; use mockito::Server; + use std::time::Duration; use crate::async_impl::schema_registry::{ get_schema_by_id, get_schema_by_id_and_type, SrSettings, diff --git a/src/avro_common.rs b/src/avro_common.rs index 49afe01..bfdf34a 100644 --- a/src/avro_common.rs +++ b/src/avro_common.rs @@ -119,7 +119,6 @@ pub(crate) fn values_to_bytes( avro_schema: &AvroSchema, values: Vec<(&str, Value)>, ) -> Result, SRCError> { - let mut record = match Record::new(&avro_schema.parsed) { Some(v) => v, None => { @@ -136,7 +135,6 @@ pub(crate) fn values_to_bytes( to_bytes(avro_schema, Value::from(record)) } - /// Using the schema with an item implementing serialize the item will be correctly deserialized /// according to the avro specification. pub(crate) fn item_to_bytes( @@ -155,10 +153,7 @@ pub(crate) fn item_to_bytes( } } -pub(crate) fn record_to_bytes( - avro_schema: &AvroSchema, - item: Value, -) -> Result, SRCError> { +pub(crate) fn record_to_bytes(avro_schema: &AvroSchema, item: Value) -> Result, SRCError> { to_bytes(avro_schema, item) } diff --git a/src/schema_registry_common.rs b/src/schema_registry_common.rs index 7e4bc8b..5425a25 100644 --- a/src/schema_registry_common.rs +++ b/src/schema_registry_common.rs @@ -171,24 +171,40 @@ pub(crate) fn url_for_call(call: &SrCall, base_url: &str) -> String { SrCall::GetById(id) => format!("{}/schemas/ids/{}?deleted=true", base_url, id), SrCall::GetLatest(subject) => { // Use escape sequences instead of slashes in the subject - format!("{}/subjects/{}/versions/latest", base_url, subject.replace("/", "%2F")) + format!( + "{}/subjects/{}/versions/latest", + base_url, + subject.replace("/", "%2F") + ) } SrCall::GetBySubjectAndVersion(subject, version) => { // Use escape sequences instead of slashes in the subject - format!("{}/subjects/{}/versions/{}", base_url, subject.replace("/", "%2F"), version) + format!( + "{}/subjects/{}/versions/{}", + base_url, + subject.replace("/", "%2F"), + version + ) } SrCall::PostNew(subject, _) => { // Use escape sequences instead of slashes in the subject - format!("{}/subjects/{}/versions", base_url, subject.replace("/", "%2F")) + format!( + "{}/subjects/{}/versions", + base_url, + subject.replace("/", "%2F") + ) } SrCall::PostForVersion(subject, _) => { // Use escape sequences instead of slashes in the subject - format!("{}/subjects/{}?deleted=false", base_url, subject.replace("/", "%2F")) + format!( + "{}/subjects/{}?deleted=false", + base_url, + subject.replace("/", "%2F") + ) } } } - /// Creates payload that can be included as a key or value on a kafka record pub fn get_payload(id: u32, encoded_bytes: Vec) -> Vec { let mut payload = vec![0u8]; diff --git a/tests/blocking/kafka_consumer.rs b/tests/blocking/kafka_consumer.rs index 5dcf9be..d2527e3 100644 --- a/tests/blocking/kafka_consumer.rs +++ b/tests/blocking/kafka_consumer.rs @@ -1,6 +1,6 @@ use rdkafka::config::{ClientConfig, RDKafkaLogLevel}; -use rdkafka::consumer::{Consumer, DefaultConsumerContext}; use rdkafka::consumer::base_consumer::BaseConsumer; +use rdkafka::consumer::{Consumer, DefaultConsumerContext}; type TestConsumer = BaseConsumer;