Skip to content

Commit

Permalink
fix: missing semicolon in tuple structs
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaka91 committed Oct 6, 2023
1 parent 0d83290 commit d616e92
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/stef-build/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ fn compile_fields(fields: &Fields<'_>, for_struct: bool) -> TokenStream {
quote! { #ty }
});

quote! { (#(#fields,)*) }
if for_struct {
quote! { (#(#fields,)*); }
} else {
quote! { (#(#fields,)*) }
}
}
Fields::Unit => {
if for_struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
source: crates/stef-build/tests/compiler.rs
expression: "/// Basic struct.\nstruct Sample(u32 @1, bool @2)"
input_file: crates/stef-parser/tests/inputs/struct-tuple.stef
---
/// Basic struct.
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub struct Sample(u32, bool);
#[automatically_derived]
impl ::stef::Encode for Sample {
fn encode(&self, w: &mut impl ::stef::BufMut) {
::stef::buf::encode_field(w, 1, |w| { ::stef::buf::encode_u32(w, self.0) });
::stef::buf::encode_field(w, 2, |w| { ::stef::buf::encode_bool(w, self.1) });
::stef::buf::encode_u32(w, ::stef::buf::END_MARKER);
}
}
#[automatically_derived]
impl ::stef::Decode for Sample {
fn decode(r: &mut impl ::stef::Buf) -> ::stef::buf::Result<Self> {
let mut n0: Option<u32> = None;
let mut n1: Option<bool> = None;
loop {
match ::stef::buf::decode_id(r)? {
::stef::buf::END_MARKER => break,
1 => n0 = Some(::stef::buf::decode_u32(r)?),
2 => n1 = Some(::stef::buf::decode_bool(r)?),
_ => continue,
}
}
Ok(
Self(
n0
.ok_or(::stef::buf::Error::MissingField {
id: 1,
name: None,
})?,
n1
.ok_or(::stef::buf::Error::MissingField {
id: 2,
name: None,
})?,
),
)
}
}

0 comments on commit d616e92

Please sign in to comment.