From 49495e6ac294c52c5fd3d5a6fd2b6b394f324f48 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Mon, 25 Mar 2024 19:14:41 +0700 Subject: [PATCH] Fix enum variants flagged fields writing --- proc/src/tl_write.rs | 7 +++++-- test_suite/tests/tl_write.rs | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/proc/src/tl_write.rs b/proc/src/tl_write.rs index 283875d..f40c0ec 100644 --- a/proc/src/tl_write.rs +++ b/proc/src/tl_write.rs @@ -53,8 +53,11 @@ fn build_generics(container: &ast::Container) -> syn::Generics { fn build_enum(container: &ast::Container, variants: &[ast::Variant]) -> TokenStream { let build_field = |field: &ast::Field| match &field.member { - syn::Member::Named(member) => quote! { #member }, - syn::Member::Unnamed(index) => quote::format_ident!("field_{}", index).to_token_stream(), + syn::Member::Named(member) => quote! { &#member }, + syn::Member::Unnamed(index) => { + let member = quote::format_ident!("field_{}", index).to_token_stream(); + quote! { &#member } + } }; let max_size_hint = match &container.attrs.size_hint { diff --git a/test_suite/tests/tl_write.rs b/test_suite/tests/tl_write.rs index 4c23d0d..b95221d 100644 --- a/test_suite/tests/tl_write.rs +++ b/test_suite/tests/tl_write.rs @@ -100,6 +100,17 @@ mod tests { value_2: Option, } + #[derive(TlWrite)] + enum EnumWithFlags { + Named { + #[tl(flags)] + flags: (), + #[tl(flags_bit = 0)] + value_1: Option, + }, + Unnamed(#[tl(flags)] (), #[tl(flags_bit = 0)] Option), + } + #[derive(TlWrite)] struct StructWithMultipleFlags { #[tl(flags, default_flags = 0x40000000)]