Kriskras99 commented on code in PR #561:
URL: https://github.com/apache/avro-rs/pull/561#discussion_r3477345034
##########
avro_derive/src/enums/plain.rs:
##########
@@ -17,25 +17,27 @@
use crate::attributes::{NamedTypeOptions, VariantOptions};
use crate::case::RenameRule;
-use crate::enums::default_enum_variant;
+use crate::implementation::Implementation;
use crate::{aliases, preserve_optional};
-use proc_macro2::{Span, TokenStream};
+use proc_macro2::{Ident, Span};
use quote::quote;
use syn::spanned::Spanned;
-use syn::{DataEnum, Fields};
+use syn::{Attribute, DataEnum, Fields, Generics, Meta};
-pub fn schema_def(
- container_attrs: &NamedTypeOptions,
- data_enum: &DataEnum,
- ident_span: Span,
-) -> Result<TokenStream, Vec<syn::Error>> {
+pub fn to_implementation(
+ input_span: Span,
+ ident: Ident,
+ generics: Generics,
+ container_attrs: NamedTypeOptions,
+ data: DataEnum,
+) -> Result<Implementation, Vec<syn::Error>> {
let doc = preserve_optional(container_attrs.doc.as_ref());
let enum_aliases = aliases(&container_attrs.aliases);
- if data_enum.variants.iter().all(|v| Fields::Unit == v.fields) {
- let default_value = default_enum_variant(data_enum, ident_span)?;
+ if data.variants.iter().all(|v| Fields::Unit == v.fields) {
+ let default_value = default_enum_variant(&data, input_span)?;
let default = preserve_optional(default_value);
Review Comment:
Yes it should! This did cause a kind of snowball effect as to fix this:
- I needed the `serde_json::Value` instead of a `TokenStream`
- Needed to restructure the plain enum code
- Decided to also implement a `Value` to `TokenStream` function so we don't
need to parse at runtime
- I also made the serializer less struct (but keeping a fast path!),
allowing `skip` to work on enum variants
--
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]