Skip to content

Commit 7769d2c

Browse files
committed
fix(encoding): Fix incorrect items count
1 parent bcfff7d commit 7769d2c

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

crates/ast_node/src/encoding/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
4040
syn::parse_quote! { #ident ( #(#names),* ) }
4141
};
4242

43-
let count = data.fields.len();
43+
let count = data.fields.iter().filter(|field| !is_ignore(&field.attrs)).count();
4444
let head: Option<syn::Stmt> = (count != 1).then(|| {
4545
syn::parse_quote! {
4646
let len = <cbor4ii::core::types::Array<()>>::len(reader)?.unwrap();
@@ -193,7 +193,7 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
193193
}
194194
})
195195
.collect::<Vec<_>>();
196-
let count = field.fields.len();
196+
let count = names.len();
197197

198198
let stmt = field.fields.iter()
199199
.zip(names.iter())

crates/ast_node/src/encoding/encode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
2828
cbor4ii::core::enc::Encode::encode(&#fieldpath, writer)?;
2929
},
3030
}
31-
});
32-
let count = data.fields.len();
31+
})
32+
.collect::<Vec<_>>();
33+
let count = fields.len();
3334
let head: Option<syn::Stmt> = (count != 1).then(|| {
3435
syn::parse_quote! {
3536
<cbor4ii::core::types::Array<()>>::bounded(#count, writer)?;

0 commit comments

Comments
 (0)