This is an automated email from the ASF dual-hosted git repository. kriskras99 pushed a commit to branch feat/derive_with in repository https://gitbox.apache.org/repos/asf/avro-rs.git
commit f3dd04f6db7d2604fdf87d8a003dced94d8b66ea Author: default <[email protected]> AuthorDate: Fri Jan 9 13:47:54 2026 +0000 feat!: Use the `Fixed` representation for `uuid::Uuid` --- avro/src/schema.rs | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/avro/src/schema.rs b/avro/src/schema.rs index cba069b..93dba0f 100644 --- a/avro/src/schema.rs +++ b/avro/src/schema.rs @@ -2662,7 +2662,6 @@ pub mod derive { impl_schema!(f32, Schema::Float); impl_schema!(f64, Schema::Double); impl_schema!(String, Schema::String); - impl_schema!(uuid::Uuid, Schema::Uuid(UuidSchema::String)); impl<T> AvroSchemaComponent for Vec<T> where @@ -2757,6 +2756,9 @@ pub mod derive { } impl AvroSchemaComponent for core::time::Duration { + /// The schema is [`Schema::Duration`] with the name `duration`. + /// + /// This is a lossy conversion as this Avro type does not store the amount of nanoseconds. fn get_schema_in_ctxt( named_schemas: &mut Names, enclosing_namespace: &Namespace, @@ -2765,17 +2767,49 @@ pub mod derive { name: "duration".to_string(), namespace: enclosing_namespace.clone(), }; - named_schemas - .entry(name.clone()) - .or_insert(Schema::Duration(FixedSchema { - name, + if named_schemas.contains_key(&name) { + Schema::Ref { name } + } else { + let schema = Schema::Duration(FixedSchema { + name: name.clone(), aliases: None, doc: None, size: 12, default: None, attributes: Default::default(), - })) - .clone() + }); + named_schemas.insert(name.clone(), schema.clone()); + schema + } + } + } + + impl AvroSchemaComponent for uuid::Uuid { + /// The schema is [`Schema::Uuid`] with the name `uuid`. + /// + /// The underlying schema is [`Schema::Fixed`] with a size of 16. + fn get_schema_in_ctxt( + named_schemas: &mut Names, + enclosing_namespace: &Namespace, + ) -> Schema { + let name = Name { + name: "uuid".to_string(), + namespace: enclosing_namespace.clone(), + }; + if named_schemas.contains_key(&name) { + Schema::Ref { name } + } else { + let schema = Schema::Uuid(UuidSchema::Fixed(FixedSchema { + name: name.clone(), + aliases: None, + doc: None, + size: 16, + default: None, + attributes: Default::default(), + })); + named_schemas.insert(name.clone(), schema.clone()); + schema + } } } }
