MCPcopy Create free account
hub / github.com/apache/fory / gen_variants_fields_info

Function gen_variants_fields_info

rust/fory-derive/src/object/derive_enum.rs:236–277  ·  view source on GitHub ↗
(enum_name: &syn::Ident, data_enum: &DataEnum)

Source from the content-addressed store, hash-verified

234}
235
236pub fn gen_variants_fields_info(enum_name: &syn::Ident, data_enum: &DataEnum) -> TokenStream {
237 let variant_info: Vec<TokenStream> = data_enum
238 .variants
239 .iter()
240 .filter(|v| !is_runtime_unknown_variant(v))
241 .map(|v| {
242 let variant_name = v.ident.to_string();
243 match &v.fields {
244 Fields::Named(_fields_named) => {
245 // Generate meta type identifier for this named variant
246 let meta_type_ident = Ident::new(
247 &format!("{}_{}VariantMeta", enum_name, v.ident),
248 proc_macro2::Span::call_site()
249 );
250 quote! {
251 (
252 #variant_name.to_string(),
253 ::std::any::TypeId::of::<#meta_type_ident>(),
254 <#meta_type_ident as fory_core::serializer::enum_::NamedEnumVariantMetaTrait>::fory_fields_info(type_resolver)?
255 )
256 }
257 }
258 _ => {
259 // Unit or unnamed variants - return empty field info
260 quote! {
261 (
262 #variant_name.to_string(),
263 ::std::any::TypeId::of::<()>(), // Placeholder type ID
264 ::std::vec::Vec::new()
265 )
266 }
267 }
268 }
269 })
270 .collect();
271
272 quote! {
273 ::std::result::Result::Ok(::std::vec![
274 #(#variant_info),*
275 ])
276 }
277}
278
279pub fn gen_reserved_space() -> TokenStream {
280 quote! {

Callers 1

derive_serializerFunction · 0.85

Calls 3

mapMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected