Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): do not require Default for derive(Compact) #3419

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/storage/codecs/derive/src/compact/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl<'a> EnumHandler<'a> {
// Unamed type
self.enum_lines.push(quote! {
#current_variant_index => {
let mut inner = #field_type::default();
(inner, buf) = #field_type::#from_compact_ident(buf, buf.len());
let (inner, new_buf) = #field_type::#from_compact_ident(buf, buf.len());
buf = new_buf;
#ident::#variant_name(inner)
}
});
Expand Down
10 changes: 5 additions & 5 deletions crates/storage/codecs/derive/src/compact/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,21 @@ impl<'a> StructHandler<'a> {
})
} else {
let ident_type = format_ident!("{ftype}");
self.lines.push(quote! {
let mut #name = #ident_type::default();
});
if !is_flag_type(ftype) {
// It's a type that handles its own length requirements. (h256, Custom, ...)
self.lines.push(quote! {
(#name, buf) = #ident_type::#from_compact_ident(buf, buf.len());
let (#name, new_buf) = #ident_type::#from_compact_ident(buf, buf.len());
})
} else if *is_compact {
self.lines.push(quote! {
(#name, buf) = #ident_type::#from_compact_ident(buf, flags.#len() as usize);
let (#name, new_buf) = #ident_type::#from_compact_ident(buf, flags.#len() as usize);
});
} else {
todo!()
}
self.lines.push(quote! {
buf = new_buf;
});
}
}
}