Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ clippy.manual_assert = "warn"
clippy.enum_glob_use = "warn"
clippy.needless_pass_by_value = "warn"
clippy.single_match_else = "warn"
clippy.uninlined_format_args = "warn"
5 changes: 2 additions & 3 deletions avro/examples/generate_interop_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ fn create_datum(schema: &Schema) -> Record<'_> {
fn main() -> Result<(), Box<dyn Error>> {
let interop_root_folder: String = std::env::var("INTEROP_ROOT_FOLDER")?;
let schema_str = std::fs::read_to_string(format!(
"{}/share/test/schemas/interop.avsc",
&interop_root_folder
"{interop_root_folder}/share/test/schemas/interop.avsc",
))
.expect("Unable to read the interop Avro schema");
let schema = Schema::parse_str(schema_str.as_str())?;
Expand All @@ -94,7 +93,7 @@ fn main() -> Result<(), Box<dyn Error>> {
format!("_{codec_name}")
};

let file_name = format!("{}/rust{suffix}.avro", &data_folder);
let file_name = format!("{data_folder}/rust{suffix}.avro");
let output_file = std::fs::File::create(&file_name)?;

let mut writer = Writer::with_codec(&schema, BufWriter::new(output_file), codec)?;
Expand Down
5 changes: 2 additions & 3 deletions avro/examples/test_interop_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let ext = path.extension().and_then(OsStr::to_str).unwrap();

if ext == "avro" {
println!("Checking {:?}", &path);
println!("Checking {path:?}");
let content = std::fs::File::open(&path)?;
let reader = Reader::new(BufReader::new(&content))?;

Expand All @@ -51,8 +51,7 @@ fn main() -> Result<(), Box<dyn Error>> {
for value in reader {
if let Err(e) = value {
errors.push(format!(
"There is a problem with reading of '{:?}', \n {:?}\n",
&path, e
"There is a problem with reading of '{path:?}', \n {e:?}\n"
));
}
}
Expand Down
30 changes: 10 additions & 20 deletions avro/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ mod tests {
assert_eq!(
outer_value1,
decode(&schema, &mut bytes).expect(&format!(
"Failed to decode using recursive definitions with schema:\n {:?}\n",
&schema
"Failed to decode using recursive definitions with schema:\n {schema:?}\n"
))
);

Expand All @@ -521,8 +520,7 @@ mod tests {
assert_eq!(
outer_value2,
decode(&schema, &mut bytes).expect(&format!(
"Failed to decode using recursive definitions with schema:\n {:?}\n",
&schema
"Failed to decode using recursive definitions with schema:\n {schema:?}\n"
))
);

Expand Down Expand Up @@ -571,8 +569,7 @@ mod tests {
assert_eq!(
outer_value,
decode(&schema, &mut bytes).expect(&format!(
"Failed to decode using recursive definitions with schema:\n {:?}\n",
&schema
"Failed to decode using recursive definitions with schema:\n {schema:?}\n"
))
);

Expand Down Expand Up @@ -624,8 +621,7 @@ mod tests {
assert_eq!(
outer_value,
decode(&schema, &mut bytes).expect(&format!(
"Failed to decode using recursive definitions with schema:\n {:?}\n",
&schema
"Failed to decode using recursive definitions with schema:\n {schema:?}\n"
))
);

Expand Down Expand Up @@ -716,8 +712,7 @@ mod tests {
assert_eq!(
outer_record_variation_1,
decode(&schema, &mut bytes).expect(&format!(
"Failed to Decode with recursively defined namespace with schema:\n {:?}\n",
&schema
"Failed to Decode with recursively defined namespace with schema:\n {schema:?}\n"
))
);

Expand All @@ -728,8 +723,7 @@ mod tests {
assert_eq!(
outer_record_variation_2,
decode(&schema, &mut bytes).expect(&format!(
"Failed to Decode with recursively defined namespace with schema:\n {:?}\n",
&schema
"Failed to Decode with recursively defined namespace with schema:\n {schema:?}\n"
))
);

Expand All @@ -740,8 +734,7 @@ mod tests {
assert_eq!(
outer_record_variation_3,
decode(&schema, &mut bytes).expect(&format!(
"Failed to Decode with recursively defined namespace with schema:\n {:?}\n",
&schema
"Failed to Decode with recursively defined namespace with schema:\n {schema:?}\n"
))
);

Expand Down Expand Up @@ -833,8 +826,7 @@ mod tests {
assert_eq!(
outer_record_variation_1,
decode(&schema, &mut bytes).expect(&format!(
"Failed to Decode with recursively defined namespace with schema:\n {:?}\n",
&schema
"Failed to Decode with recursively defined namespace with schema:\n {schema:?}\n"
))
);

Expand All @@ -845,8 +837,7 @@ mod tests {
assert_eq!(
outer_record_variation_2,
decode(&schema, &mut bytes).expect(&format!(
"Failed to Decode with recursively defined namespace with schema:\n {:?}\n",
&schema
"Failed to Decode with recursively defined namespace with schema:\n {schema:?}\n"
))
);

Expand All @@ -857,8 +848,7 @@ mod tests {
assert_eq!(
outer_record_variation_3,
decode(&schema, &mut bytes).expect(&format!(
"Failed to Decode with recursively defined namespace with schema:\n {:?}\n",
&schema
"Failed to Decode with recursively defined namespace with schema:\n {schema:?}\n"
))
);

Expand Down
5 changes: 1 addition & 4 deletions avro/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ pub(crate) mod tests {
use uuid::Uuid;

pub(crate) fn success(value: &Value, schema: &Schema) -> String {
format!(
"Value: {:?}\n should encode with schema:\n{:?}",
&value, &schema
)
format!("Value: {value:?}\n should encode with schema:\n{schema:?}")
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions avro/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4848,13 +4848,13 @@ mod tests {
}) => {
assert!(attributes.is_empty());
}
_ => panic!("Expected ArraySchema. got: {}", &fields[0].schema),
_ => panic!("Expected ArraySchema. got: {}", fields[0].schema),
}
}
_ => panic!("Expected RecordSchema. got: {}", &items),
_ => panic!("Expected RecordSchema. got: {items}"),
}
}
_ => panic!("Expected ArraySchema. got: {}", &schema1),
_ => panic!("Expected ArraySchema. got: {schema1}"),
}
let canonical_form1 = schema1.canonical_form();
let schema2 = Schema::parse_str(&canonical_form1)?;
Expand Down Expand Up @@ -4918,13 +4918,13 @@ mod tests {
}) => {
assert!(attributes.is_empty());
}
_ => panic!("Expected MapSchema. got: {}", &fields[0].schema),
_ => panic!("Expected MapSchema. got: {}", fields[0].schema),
}
}
_ => panic!("Expected RecordSchema. got: {}", &items),
_ => panic!("Expected RecordSchema. got: {items}"),
}
}
_ => panic!("Expected ArraySchema. got: {}", &schema1),
_ => panic!("Expected ArraySchema. got: {schema1}"),
}
let canonical_form1 = schema1.canonical_form();
let schema2 = Schema::parse_str(&canonical_form1)?;
Expand Down
2 changes: 1 addition & 1 deletion avro/src/schema/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl Parser {

self.register_resolving_schema(&fully_qualified_name, &aliases);

debug!("Going to parse record schema: {:?}", &fully_qualified_name);
debug!("Going to parse record schema: {fully_qualified_name:?}");

let fields: Vec<RecordField> = fields_opt
.and_then(|fields| fields.as_array())
Expand Down
4 changes: 2 additions & 2 deletions avro/src/serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ impl<'de> de::Deserializer<'de> for Deserializer<'de> {
Value::Record(fields) => visitor.visit_map(RecordDeserializer::new(fields)),
_ => Err(de::Error::custom(format_args!(
"Expected a record or a map. Got: {:?}",
&self.input
self.input
))),
}
}
Expand Down Expand Up @@ -1877,7 +1877,7 @@ mod tests {

#[test]
fn avro_rs_414_deserialize_char_from_bytes() -> TestResult {
let value = Value::Bytes([b'a'].to_vec());
let value = Value::Bytes(b"a".to_vec());
let result = from_value::<char>(&value)?;
assert_eq!(result, 'a');

Expand Down
4 changes: 2 additions & 2 deletions avro/src/writer/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ mod tests {
let mut expected = Vec::new();
zig_i64(27, &mut expected)?;
zig_i64(3, &mut expected)?;
expected.extend([b'f', b'o', b'o']);
expected.extend(b"foo");

let written = GenericDatumWriter::builder(&schema)
.build()?
Expand Down Expand Up @@ -308,7 +308,7 @@ mod tests {
let mut expected = Vec::new();
zig_i64(27, &mut expected)?;
zig_i64(3, &mut expected)?;
expected.extend([b'f', b'o', b'o']);
expected.extend(b"foo");

let bytes = GenericDatumWriter::builder(&schema)
.build()?
Expand Down
2 changes: 1 addition & 1 deletion avro/tests/append_to_existing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn check(value: &AvroResult<Value>, expected: i32) {
Ok(value) => match value {
Value::Record(fields) => match &fields[0] {
(_, Value::Int(actual)) => assert_eq!(&expected, actual),
_ => panic!("The field value type must be an Int: {:?}!", &fields[0]),
_ => panic!("The field value type must be an Int: {:?}!", fields[0]),
},
_ => panic!("The value type must be a Record: {value:?}!"),
},
Expand Down
2 changes: 1 addition & 1 deletion avro/tests/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn test_schema() -> TestResult {
for f in directory {
let entry: DirEntry = match f {
Ok(entry) => entry,
Err(e) => core::panic!("Can't get file {}", e),
Err(e) => core::panic!("Can't get file {e}"),
};
log::debug!("{:?}", entry.file_name());
if let Ok(ft) = entry.file_type()
Expand Down
131 changes: 73 additions & 58 deletions avro_derive/src/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,65 +159,80 @@ impl Display for ParseError {
}
}

#[test]
fn rename_variants() {
for &(original, lower, upper, camel, snake, screaming, kebab, screaming_kebab) in &[
(
"Outcome", "outcome", "OUTCOME", "outcome", "outcome", "OUTCOME", "outcome", "OUTCOME",
),
(
"VeryTasty",
"verytasty",
"VERYTASTY",
"veryTasty",
"very_tasty",
"VERY_TASTY",
"very-tasty",
"VERY-TASTY",
),
("A", "a", "A", "a", "a", "A", "a", "A"),
("Z42", "z42", "Z42", "z42", "z42", "Z42", "z42", "Z42"),
] {
assert_eq!(None.apply_to_variant(original), original);
assert_eq!(LowerCase.apply_to_variant(original), lower);
assert_eq!(UpperCase.apply_to_variant(original), upper);
assert_eq!(PascalCase.apply_to_variant(original), original);
assert_eq!(CamelCase.apply_to_variant(original), camel);
assert_eq!(SnakeCase.apply_to_variant(original), snake);
assert_eq!(ScreamingSnakeCase.apply_to_variant(original), screaming);
assert_eq!(KebabCase.apply_to_variant(original), kebab);
assert_eq!(
ScreamingKebabCase.apply_to_variant(original),
screaming_kebab
);
#[cfg(test)]
mod tests {
use crate::case::RenameRule::{
CamelCase, KebabCase, LowerCase, PascalCase, ScreamingKebabCase, ScreamingSnakeCase,
SnakeCase, UpperCase,
};

#[test]
fn rename_variants() {
for &(original, lower, upper, camel, snake, screaming, kebab, screaming_kebab) in &[
(
"Outcome", "outcome", "OUTCOME", "outcome", "outcome", "OUTCOME", "outcome",
"OUTCOME",
),
(
"VeryTasty",
"verytasty",
"VERYTASTY",
"veryTasty",
"very_tasty",
"VERY_TASTY",
"very-tasty",
"VERY-TASTY",
),
("A", "a", "A", "a", "a", "A", "a", "A"),
("Z42", "z42", "Z42", "z42", "z42", "Z42", "z42", "Z42"),
] {
assert_eq!(
crate::case::RenameRule::None.apply_to_variant(original),
original
);
assert_eq!(LowerCase.apply_to_variant(original), lower);
assert_eq!(UpperCase.apply_to_variant(original), upper);
assert_eq!(PascalCase.apply_to_variant(original), original);
assert_eq!(CamelCase.apply_to_variant(original), camel);
assert_eq!(SnakeCase.apply_to_variant(original), snake);
assert_eq!(ScreamingSnakeCase.apply_to_variant(original), screaming);
assert_eq!(KebabCase.apply_to_variant(original), kebab);
assert_eq!(
ScreamingKebabCase.apply_to_variant(original),
screaming_kebab
);
}
}
}

#[test]
fn rename_fields() {
for &(original, upper, pascal, camel, screaming, kebab, screaming_kebab) in &[
(
"outcome", "OUTCOME", "Outcome", "outcome", "OUTCOME", "outcome", "OUTCOME",
),
(
"very_tasty",
"VERY_TASTY",
"VeryTasty",
"veryTasty",
"VERY_TASTY",
"very-tasty",
"VERY-TASTY",
),
("a", "A", "A", "a", "A", "a", "A"),
("z42", "Z42", "Z42", "z42", "Z42", "z42", "Z42"),
] {
assert_eq!(None.apply_to_field(original), original);
assert_eq!(UpperCase.apply_to_field(original), upper);
assert_eq!(PascalCase.apply_to_field(original), pascal);
assert_eq!(CamelCase.apply_to_field(original), camel);
assert_eq!(SnakeCase.apply_to_field(original), original);
assert_eq!(ScreamingSnakeCase.apply_to_field(original), screaming);
assert_eq!(KebabCase.apply_to_field(original), kebab);
assert_eq!(ScreamingKebabCase.apply_to_field(original), screaming_kebab);
#[test]
fn rename_fields() {
for &(original, upper, pascal, camel, screaming, kebab, screaming_kebab) in &[
(
"outcome", "OUTCOME", "Outcome", "outcome", "OUTCOME", "outcome", "OUTCOME",
),
(
"very_tasty",
"VERY_TASTY",
"VeryTasty",
"veryTasty",
"VERY_TASTY",
"very-tasty",
"VERY-TASTY",
),
("a", "A", "A", "a", "A", "a", "A"),
("z42", "Z42", "Z42", "z42", "Z42", "z42", "Z42"),
] {
assert_eq!(
crate::case::RenameRule::None.apply_to_field(original),
original
);
assert_eq!(UpperCase.apply_to_field(original), upper);
assert_eq!(PascalCase.apply_to_field(original), pascal);
assert_eq!(CamelCase.apply_to_field(original), camel);
assert_eq!(SnakeCase.apply_to_field(original), original);
assert_eq!(ScreamingSnakeCase.apply_to_field(original), screaming);
assert_eq!(KebabCase.apply_to_field(original), kebab);
assert_eq!(ScreamingKebabCase.apply_to_field(original), screaming_kebab);
}
}
}
Loading