martin-g commented on code in PR #401:
URL: https://github.com/apache/avro-rs/pull/401#discussion_r2692179731
##########
avro_derive/tests/derive.rs:
##########
@@ -1827,3 +1827,88 @@ 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());
+}
+
+#[test]
+fn avro_rs_401_supported_type_variants() {
+ #[expect(dead_code, reason = "We only check the schema")]
+ #[derive(AvroSchema)]
+ struct Foo<'a> {
+ one: f32,
+ two: std::string::String,
+ three: &'static i32,
+ four: &'a str,
+ five: &'a mut f64,
+ six: [u8; 5],
+ seven: [u8],
Review Comment:
I found the answer:
```rust
struct MyData {
id: u32, // Sized field (fixed offset)
// Some other sized fields...
content: [u8], // UNSIZED field (must be last)
}
// You can't do this:
// struct Invalid {
// content: [u8],
// id: u32,
// }
// You interact via pointers (or references):
let data: &MyData = &MyData { id: 1, content: [10, 20, 30] };
// Or with Box:
let boxed_data: Box<MyData> = Box::new(MyData { id: 2, content: [40, 50] });
```
I learnt something new today!
--
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]