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

support for generics in compile based IDL generation #2013

Closed
kklas opened this issue Jun 29, 2022 · 1 comment
Closed

support for generics in compile based IDL generation #2013

kklas opened this issue Jun 29, 2022 · 1 comment

Comments

@kklas
Copy link
Contributor

kklas commented Jun 29, 2022

The compile IDL generation method (#2011) doesn't work for types with generics.

The code it generates is similar to this:

impl SomeAnchorSerializeType {
   <... idl gen helper methods ...>
}

When the type has generics it will generate this:

impl<T> SomeAnchorSerializeType<T: AnchorSerializeType> {
   <... idl gen helper methods ...>
}

Which is fine, but we can't call these methods because we'd have to specify which exact type T to call them for which we don't know.
And in practice knowing the type T shouldn't be necessary because the "idl gen helper methods" don't rely on T. It's just that rust won't allow us to call them without specifying T.

But we can go around this by generating an empty placeholder type and then do impl on it instead of the original type:

pub struct __anchor_private_idl_gen_SomeAnchorSerializeType {}

impl __anchor_private_idl_gen_SomeAnchorSerializeType {
   <... idl gen helper methods ...>
}

Then we call the methods on the placeholder type instead of the original one.

@kklas
Copy link
Contributor Author

kklas commented Mar 10, 2023

Solved in #2011

@kklas kklas closed this as completed Mar 10, 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

No branches or pull requests

1 participant