@@ -39,11 +39,18 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
39
39
} ;
40
40
41
41
let count = data. fields . len ( ) ;
42
- let head: Option < syn:: Expr > = ( count != 1 ) . then ( || {
43
- syn:: parse_quote! { {
44
- let n = <cbor4ii:: core:: types:: Array <( ) >>:: len( reader) ?;
45
- debug_assert_eq!( n, Some ( #count) ) ;
46
- } }
42
+ let head: Option < syn:: Stmt > = ( count != 1 ) . then ( || {
43
+ syn:: parse_quote! {
44
+ let len = <cbor4ii:: core:: types:: Array <( ) >>:: len( reader) ?. unwrap( ) ;
45
+ }
46
+ } ) ;
47
+ let tail: Option < syn:: Stmt > = head. is_some ( ) . then ( || {
48
+ syn:: parse_quote! {
49
+ // ignore unknown field
50
+ for _ in 0 ..( len - #count) {
51
+ cbor4ii:: core:: dec:: IgnoredAny :: decode( reader) ?;
52
+ }
53
+ }
47
54
} ) ;
48
55
49
56
syn:: parse_quote! {
@@ -53,8 +60,12 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
53
60
-> Result <Self , cbor4ii:: core:: error:: DecodeError <R :: Error >>
54
61
{
55
62
#head;
56
- #( #fields) *
57
- Ok ( #build_struct)
63
+ let value = {
64
+ #( #fields) *
65
+ #build_struct
66
+ } ;
67
+ #tail
68
+ Ok ( value)
58
69
}
59
70
}
60
71
}
@@ -180,7 +191,7 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
180
191
}
181
192
} )
182
193
. collect :: < Vec < _ > > ( ) ;
183
- let num = field. fields . len ( ) ;
194
+ let count = field. fields . len ( ) ;
184
195
185
196
let stmt = field. fields . iter ( )
186
197
. zip ( names. iter ( ) )
@@ -203,10 +214,18 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
203
214
204
215
syn:: parse_quote!{
205
216
#idx => {
206
- let len = cbor4ii:: core:: types:: Array :: len( reader) ?;
207
- debug_assert_eq!( len, Some ( #num) ) ;
208
- #( #stmt) *
209
- #build_struct
217
+ let len = cbor4ii:: core:: types:: Array :: len( reader) ?. unwrap( ) ;
218
+ let value = {
219
+ #( #stmt) *
220
+ #build_struct
221
+ } ;
222
+
223
+ // ignore unknown field
224
+ for _ in 0 ..( len - #count) {
225
+ cbor4ii:: core:: dec:: IgnoredAny :: decode( reader) ?;
226
+ }
227
+
228
+ value
210
229
} ,
211
230
}
212
231
}
0 commit comments