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

Opt out from default derives and attributes #925

Merged

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
cli/src/commands/codegen.rs Outdated Show resolved Hide resolved
macro/src/lib.rs Outdated Show resolved Hide resolved
cli/src/commands/codegen.rs Outdated Show resolved Hide resolved
cli/src/commands/codegen.rs Outdated Show resolved Hide resolved
macro/src/lib.rs Outdated Show resolved Hide resolved
@jsdw
Copy link
Collaborator

jsdw commented Apr 24, 2023

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

@jsdw jsdw requested a review from a team April 24, 2023 10:13
/// Additional derives for a given type.
///
/// Example `--derive-for-type my_module::my_type=serde::Serialize`.
#[clap(long = "derive-for-type", value_parser = derive_for_type_parser)]
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