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

Handle StorageEntry empty keys #565

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 15 additions & 7 deletions codegen/src/api/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,21 @@ fn generate_storage_entry_fns(
None => quote!(#t),
}
});

let entry_struct = quote! {
pub struct #entry_struct_ident <'a>( #( pub &'a #field_types ),* );

// There cannot be a reference without a parameter.
let should_ref = !fields.is_empty();
let (entry_struct, constructor) = if should_ref {
(
quote! {
pub struct #entry_struct_ident <'a>( #( pub &'a #field_types ),* );
},
quote!( #entry_struct_ident( #( #field_names ),* ) ),
)
} else {
(
quote!( pub struct #entry_struct_ident; ),
quote!( #entry_struct_ident ),
)
};
let constructor =
quote!( #entry_struct_ident( #( #field_names ),* ) );

let key_impl = if hashers.len() == fields.len() {
// If the number of hashers matches the number of fields, we're dealing with
Expand Down Expand Up @@ -214,7 +222,7 @@ fn generate_storage_entry_fns(
)
};

(fields, entry_struct, constructor, key_impl, true)
(fields, entry_struct, constructor, key_impl, should_ref)
}
_ => {
let (lifetime_param, lifetime_ref) = (quote!(<'a>), quote!(&'a));
Expand Down
Loading