Skip to content

Commit

Permalink
fix: make tuple struct fields public in Rust
Browse files Browse the repository at this point in the history
If defining a unnamed struct (tuple struct), the Rust generator wasn't
marking the fields as public, making the inaccessible.
  • Loading branch information
dnaka91 committed Nov 2, 2023
1 parent 6ddaa4a commit 7dcc660
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions crates/stef-build/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ fn compile_variant(
comment,
name,
fields,
id: _,
..
}: &Variant<'_>,
) -> TokenStream {
Expand Down Expand Up @@ -219,7 +218,6 @@ fn compile_fields(fields: &Fields<'_>, for_struct: bool) -> TokenStream {
comment,
name,
ty,
id: _,
..
}| {
let comment = compile_comment(comment);
Expand All @@ -238,9 +236,10 @@ fn compile_fields(fields: &Fields<'_>, for_struct: bool) -> TokenStream {
} }
}
Fields::Unnamed(unnamed) => {
let fields = unnamed.iter().map(|UnnamedField { ty, id: _, .. }| {
let fields = unnamed.iter().map(|UnnamedField { ty, .. }| {
let public = for_struct.then(|| quote! { pub });
let ty = compile_data_type(ty);
quote! { #ty }
quote! { #public #ty }
});

if for_struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ::stef::buf::{Decode, Encode};
/// Basic struct.
#[derive(Clone, Debug, PartialEq)]
#[allow(clippy::module_name_repetitions, clippy::option_option)]
pub struct Sample(u32, bool);
pub struct Sample(pub u32, pub bool);
#[automatically_derived]
impl ::stef::Encode for Sample {
#[allow(
Expand Down

0 comments on commit 7dcc660

Please sign in to comment.