This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 00969b7 AVRO-3240: Fix code formatting
00969b7 is described below
commit 00969b71fb23a15a4741b4c8e906b243db5386db
Author: Martin Tzvetanov Grigorov <[email protected]>
AuthorDate: Fri Jan 7 15:33:00 2022 +0200
AVRO-3240: Fix code formatting
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
---
lang/rust/src/decode.rs | 89 ++++++++++++++++++++++++-------------------------
lang/rust/src/reader.rs | 15 +++++----
2 files changed, 53 insertions(+), 51 deletions(-)
diff --git a/lang/rust/src/decode.rs b/lang/rust/src/decode.rs
index 71ee4c1..0714dcd 100644
--- a/lang/rust/src/decode.rs
+++ b/lang/rust/src/decode.rs
@@ -23,7 +23,12 @@ use crate::{
util::{safe_len, zag_i32, zag_i64},
AvroResult, Error,
};
-use std::{collections::HashMap, convert::TryFrom, io::{ErrorKind, Read},
str::FromStr};
+use std::{
+ collections::HashMap,
+ convert::TryFrom,
+ io::{ErrorKind, Read},
+ str::FromStr,
+};
use uuid::Uuid;
#[inline]
@@ -67,23 +72,20 @@ pub fn decode<R: Read>(schema: &Schema, reader: &mut R) ->
AvroResult<Value> {
Schema::Null => Ok(Value::Null),
Schema::Boolean => {
let mut buf = [0u8; 1];
- match reader
- .read_exact(&mut buf[..]) {
- Ok(_) => {
- match buf[0] {
- 0u8 => Ok(Value::Boolean(false)),
- 1u8 => Ok(Value::Boolean(true)),
- _ => Err(Error::BoolValue(buf[0])),
- }
- },
- Err(io_err) => {
- if let ErrorKind::UnexpectedEof = io_err.kind() {
- Ok(Value::Null)
- } else {
- Err(Error::ReadBoolean(io_err))
- }
- },
+ match reader.read_exact(&mut buf[..]) {
+ Ok(_) => match buf[0] {
+ 0u8 => Ok(Value::Boolean(false)),
+ 1u8 => Ok(Value::Boolean(true)),
+ _ => Err(Error::BoolValue(buf[0])),
+ },
+ Err(io_err) => {
+ if let ErrorKind::UnexpectedEof = io_err.kind() {
+ Ok(Value::Null)
+ } else {
+ Err(Error::ReadBoolean(io_err))
+ }
}
+ }
}
Schema::Decimal { ref inner, .. } => match &**inner {
Schema::Fixed { .. } => match decode(inner, reader)? {
@@ -135,18 +137,16 @@ pub fn decode<R: Read>(schema: &Schema, reader: &mut R)
-> AvroResult<Value> {
let len = decode_len(reader)?;
let mut buf = vec![0u8; len];
match reader.read_exact(&mut buf) {
- Ok(_) => {
- Ok(Value::String(
- String::from_utf8(buf).map_err(Error::ConvertToUtf8)?,
- ))
- },
+ Ok(_) => Ok(Value::String(
+ String::from_utf8(buf).map_err(Error::ConvertToUtf8)?,
+ )),
Err(io_err) => {
if let ErrorKind::UnexpectedEof = io_err.kind() {
Ok(Value::Null)
} else {
Err(Error::ReadString(io_err))
}
- },
+ }
}
}
Schema::Fixed { size, .. } => {
@@ -196,29 +196,28 @@ pub fn decode<R: Read>(schema: &Schema, reader: &mut R)
-> AvroResult<Value> {
Ok(Value::Map(items))
}
- Schema::Union(ref inner) => {
- match zag_i64(reader) {
- Ok(index) => {
- let variants = inner.variants();
- let variant = variants
- .get(usize::try_from(index).map_err(|e|
Error::ConvertI64ToUsize(e, index))?)
- .ok_or_else(|| Error::GetUnionVariant {
- index,
- num_variants: variants.len(),
- })?;
- let value = decode(variant, reader)?;
- Ok(Value::Union(Box::new(value)))
- },
- Err(Error::ReadVariableIntegerBytes(io_err)) => {
- if let ErrorKind::UnexpectedEof = io_err.kind() {
- Ok(Value::Union(Box::new(Value::Null)))
- } else {
- Err(Error::ReadVariableIntegerBytes(io_err))
- }
- },
- Err(io_err) => Err(io_err),
+ Schema::Union(ref inner) => match zag_i64(reader) {
+ Ok(index) => {
+ let variants = inner.variants();
+ let variant = variants
+ .get(usize::try_from(index).map_err(|e|
Error::ConvertI64ToUsize(e, index))?)
+ .ok_or_else(|| Error::GetUnionVariant {
+ index,
+ num_variants: variants.len(),
+ })?;
+ let value = decode(variant, reader)?;
+ Ok(Value::Union(Box::new(value)))
}
- }
+ Err(Error::ReadVariableIntegerBytes(io_err)) => {
+ if let ErrorKind::UnexpectedEof = io_err.kind() {
+ Ok(Value::Union(Box::new(Value::Null)))
+ } else {
+ Err(Error::ReadVariableIntegerBytes(io_err))
+ }
+ }
+ Err(io_err) => Err(io_err),
+ },
+
Schema::Record { ref fields, .. } => {
// Benchmarks indicate ~10% improvement using this method.
let mut items = Vec::with_capacity(fields.len());
diff --git a/lang/rust/src/reader.rs b/lang/rust/src/reader.rs
index e036991..ce6a629 100644
--- a/lang/rust/src/reader.rs
+++ b/lang/rust/src/reader.rs
@@ -306,8 +306,8 @@ mod tests {
use super::*;
use crate::from_value;
use crate::{types::Record, Reader};
- use std::io::Cursor;
use serde::Deserialize;
+ use std::io::Cursor;
const SCHEMA: &str = r#"
{
@@ -376,7 +376,7 @@ mod tests {
}
"#;
#[derive(Default, Debug, Deserialize, PartialEq)]
- struct TestRecord {
+ struct TestRecord3240 {
a: i64,
b: String,
a_nullable_array: Option<Vec<String>>,
@@ -406,7 +406,7 @@ mod tests {
let schema = Schema::parse_str(TEST_RECORD_SCHEMA_3240).unwrap();
let mut encoded: &'static [u8] = &[54, 6, 102, 111, 111];
- let expected_record: TestRecord = TestRecord {
+ let expected_record: TestRecord3240 = TestRecord3240 {
a: 27i64,
b: String::from("foo"),
a_nullable_array: None,
@@ -414,9 +414,12 @@ mod tests {
};
let avro_datum = from_avro_datum(&schema, &mut encoded, None).unwrap();
- let parsed_record: TestRecord = match &avro_datum {
- Value::Record(_) => from_value::<TestRecord>(&avro_datum).unwrap(),
- unexpected => panic!("could not map avro data to struct, found
unexpected: {:?}", unexpected),
+ let parsed_record: TestRecord3240 = match &avro_datum {
+ Value::Record(_) =>
from_value::<TestRecord3240>(&avro_datum).unwrap(),
+ unexpected => panic!(
+ "could not map avro data to struct, found unexpected: {:?}",
+ unexpected
+ ),
};
assert_eq!(parsed_record, expected_record);