martin-g commented on code in PR #398:
URL: https://github.com/apache/avro-rs/pull/398#discussion_r2681729150
##########
avro_derive/src/lib.rs:
##########
@@ -264,6 +283,69 @@ fn get_data_enum_schema_def(
}
}
+/// Generate a schema definition for a type marked transparent.
+fn get_transparent_data_schema_def(
+ data: &syn::Data,
+ input_span: Span,
+) -> Result<TokenStream, Vec<syn::Error>> {
+ match data {
+ syn::Data::Struct(data_struct) => match &data_struct.fields {
+ syn::Fields::Named(fields_named) => {
+ if fields_named.named.len() != 1 {
+ return Err(vec![syn::Error::new(
+ input_span,
+ "#[serde(transparent)] is only allowed on structs with
one field",
+ )]);
+ }
+ let field = fields_named
+ .named
+ .first()
+ .expect("There is exactly one field");
+ let field_attrs = FieldOptions::new(&field.attrs,
field.span())?;
+ if field_attrs != FieldOptions::default() {
+ return Err(vec![syn::Error::new(
+ input_span,
+ "#[serde(transparent)] is incompatible with all other
attributes",
+ )]);
+ }
+ let ty = &field.ty;
+ Ok(quote! {
+ #ty::get_schema_in_ctxt(named_schemas, enclosing_namespace)
+ })
+ }
+ syn::Fields::Unnamed(_) => Err(vec![syn::Error::new(
Review Comment:
You can leave that for a follow-up PR!
--
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]