Skip to content
New issue

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

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

Already on GitHub? # to your account

Add custom derives for specific generated types #520

Merged
merged 24 commits into from
Apr 28, 2022

Conversation

ascjones
Copy link
Contributor

@ascjones ascjones commented Apr 27, 2022

Currently the user can only specify custom derives to be applied to all generated types. Sometimes it is required to use a specific generated type with certain requirements e.g. Ord, PartialOrd or serde::Serialize, serde::Deserialize, however it is not always possible/desirable to implement those on all generated types. For example when used in conjuction with substitute_type where the substituted type does not implement the required derives.

This PR adds the ability to specify derives for specific generated types, by adding the derive_for_type configuration to the subxt attribute:

#[subxt::subxt(
    runtime_metadata_path = "examples/polkadot_metadata.scale",
    derive_for_all_types = "Clone, PartialEq, Hash",
    derive_for_type(ty = "sp_runtime::DispatchError", derive = "::serde::Deserialize") // todo check this syntax
)]

Note also that generated_type_derives has been renamed to derive_for_all_types.

The final set of derives applied to a specified type will be the union of default_derives + user_derive_for_all_types + user_derive_for_type.

todo

  • example
  • unit tests
  • test with cargo-contract
  • docs

ascjones and others added 9 commits April 28, 2022 09:26
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
@ascjones ascjones marked this pull request as ready for review April 28, 2022 11:04
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

@ascjones ascjones merged commit 24317b4 into master Apr 28, 2022
@ascjones ascjones deleted the aj/specific-type-derive branch April 28, 2022 11:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants