martin-g commented on code in PR #401:
URL: https://github.com/apache/avro-rs/pull/401#discussion_r2689441927
##########
avro/src/schema.rs:
##########
Review Comment:
Do we also need similar impls for `AvroSchemaComponent for &T / &mut T` ?
To support `Option<&'a str>` for example
##########
avro_derive/src/lib.rs:
##########
@@ -267,34 +267,9 @@ fn get_data_enum_schema_def(
/// Takes in the Tokens of a type and returns the tokens of an expression with
return type `Schema`
fn type_to_schema_expr(ty: &Type) -> Result<TokenStream, Vec<syn::Error>> {
if let Type::Path(p) = ty {
- let type_string = p.path.segments.last().unwrap().ident.to_string();
-
- let schema = match &type_string[..] {
- "bool" => quote! {apache_avro::schema::Schema::Boolean},
- "i8" | "i16" | "i32" | "u8" | "u16" => quote!
{apache_avro::schema::Schema::Int},
- "u32" | "i64" => quote! {apache_avro::schema::Schema::Long},
- "f32" => quote! {apache_avro::schema::Schema::Float},
- "f64" => quote! {apache_avro::schema::Schema::Double},
- "String" | "str" => quote! {apache_avro::schema::Schema::String},
- "char" => {
- return Err(vec![syn::Error::new_spanned(
- ty,
- "AvroSchema: Cannot guarantee successful deserialization
of this type",
Review Comment:
Maybe we should implement AvroSchemaComponent for `char` and `u64` and
panic!() with these error messages ?!
##########
avro_derive/tests/derive.rs:
##########
@@ -1827,3 +1827,31 @@ fn avro_rs_247_serde_flatten_support_with_skip() {
b: 321,
});
}
+
+#[test]
+fn avro_rs_401_do_not_match_typename() {
+ #[expect(nonstandard_style, reason = "It needs to be exactly this")]
+ type f32 = f64;
+
+ #[expect(dead_code, reason = "We only check the schema")]
+ #[derive(AvroSchema)]
+ struct Foo {
+ field: f32,
+ }
+
+ let schema = r#"
+ {
+ "type":"record",
+ "name":"Foo",
+ "fields": [
+ {
+ "name":"field",
+ "type":"double"
+ }
+ ]
+ }
+ "#;
+
+ let schema = Schema::parse_str(schema).unwrap();
+ assert_eq!(schema, Foo::get_schema());
+}
Review Comment:
Let's add a test case for `str` too since it now uses AvroSchemaComponent too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]