-
Notifications
You must be signed in to change notification settings - Fork 248
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
Allow substitute types to take on 0, 1 or all of the generic params from the types they stand in for #666
Comments
No special reason other than I thought it intuitive to hijack the Option #[subxt::subxt(runtime_metadata_path = "./metadata.scale")]
pub mod node {
// The default case; any generic parameters are applied as-is to the substitute type:
#[subxt(substitute_type = "interbtc_primitives::VaultId")]
use crate::DefaultVaultId;
// We want to ignore all of the generic params and apply none of them to DefaultVaultId
#[subxt(substitute_type = "interbtc_primitives::VaultId", input_params = "A, B, C", output_params = "")]
use crate::DefaultVaultId;
// Use the "params" attr to map by position in VaultId to substitute param order.
#[subxt(substitute_type = "interbtc_primitives::VaultId", input_params = "A, B, C", output_params = "B, A")]
use crate::DefaultVaultId;
} |
I'm probably in favour of 3 still just because it feels clearest ( One question in my head with it; I wonder whether: #[subxt(substitute(input = "interbtc_primitives::VaultId", output = "crate::DefaultVaultId"))] Should fail if |
My cents on suggestion 3 as well. |
Ok, let's do 3, so the API will look something like #[subxt::subxt(runtime_metadata_path = "./metadata.scale")]
#[subxt(substitute(input = "interbtc_primitives::VaultId", output = "crate::DefaultVaultId"))]
#[subxt(substitute(input = "interbtc_primitives::VaultId<A,B,C>", output = "crate::DefaultVaultId"))]
#[subxt(substitute(input = "interbtc_primitives::VaultId<A,B,C>", output = "crate::DefaultVaultId<B, A>"))]
pub mod node { } and if the wrong number of generic arguments are provided in any case, we can throw up an error and tell the user that. |
As a side node, a nice to have may also be supporting generic params that are in scope but don't exist on the source type, so: #[subxt::subxt(runtime_metadata_path = "./metadata.scale")]
#[subxt(substitute(input = "interbtc_primitives::VaultId<A,B>", output = "crate::DefaultVaultId<crate::Foo, A>"))]
pub mod node { } Would work, using some concrete type |
See #627 for initial details.
Basically, right now we can do something like:
The effect of this is that instead of generating/using an
interbtc_primitives::VaultId
type, we'd use thecrate::DefaultValueId
instead.If the
interbtc_primitives::VaultId
type has generic params, so it would look like egstruct VaultId<A, B, C>
, then all of those generic params are assumed to exist on the substitute type; we'd expect astruct DefaultValueId<A, B, C>
.It would be useful to have more flexibility over how the generic parameters are mapped to the substitute type though (see #627 for one such issue statement).
Suggested syntax ideas:
1. pattern matching on generics.
Advantages:
Disadvantages:
2. Add a "params" attr.
Advantages:
3. use a new attribute to perform substitution
Advantages:
Disadvantages:
@ascjones @gregdhill I'd love to get your feedback; do you like the idea, and if so, do you have a preference on which syntax to go for, or reasons against any?
The text was updated successfully, but these errors were encountered: