Skip to content

Opt out from default derives and attributes#925

Merged
jsdw merged 9 commits intoparitytech:masterfrom
pmikolajczyk41:pmikolajczyk41/no-default-derive
Apr 24, 2023
Merged

Opt out from default derives and attributes#925
jsdw merged 9 commits intoparitytech:masterfrom
pmikolajczyk41:pmikolajczyk41/no-default-derive

Conversation

@pmikolajczyk41
Copy link
Contributor

This PR aims at giving the subxt user full control over derived traits and attributes for generated types. Until now, every new type was given:

#[derive(
    #crate_path::ext::scale_encode::EncodeAsType,
    #crate_path::ext::scale_decode::DecodeAsType,
    #crate_path::ext::codec::Encode,
    #crate_path::ext::codec::Decode,
    Debug
)]
#[encode_as_type(crate_path = #encode_crate_path)]
#[decode_as_type(crate_path = #decode_crate_path)]
#[codec(crate = #crate_path::ext::codec)]

This in particular meant that subxt was assumed to be available when working with just subxt_macro crate. In order to allow some flexibility, we add (both to the macro and CLI):

  • option to opt out from these defaults
  • arguments to provide both universal (for every type) and type-specific derives and attributes

@pmikolajczyk41 pmikolajczyk41 requested a review from a team as a code owner April 24, 2023 08:01
@pmikolajczyk41 pmikolajczyk41 requested a review from jsdw April 24, 2023 09:47
@jsdw
Copy link
Collaborator

jsdw commented Apr 24, 2023

A couple more naming nits for consistency with DerivesForType etc but otherwise looks great!

@pmikolajczyk41 pmikolajczyk41 requested a review from jsdw April 24, 2023 10:10
@jsdw jsdw requested a review from a team April 24, 2023 10:13
derives_for_type: Vec<(String, String)>,
/// Additional attributes for a given type.
///
/// Example `--attribute-type my_module::my_type=#[allow(clippy::all)]`.

Choose a reason for hiding this comment

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

Suggested change
/// Example `--attribute-type my_module::my_type=#[allow(clippy::all)]`.
/// Example `--attributes-for-type my_module::my_type=#[allow(clippy::all)]`.

Typo on docs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good spot; thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks!

@jsdw jsdw merged commit d3e20e9 into paritytech:master Apr 24, 2023
@pmikolajczyk41 pmikolajczyk41 deleted the pmikolajczyk41/no-default-derive branch May 8, 2023 07:43
@jsdw jsdw mentioned this pull request Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants