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

Allow default method implementations in ink! traits #1689

Open
HCastano opened this issue Feb 28, 2023 · 2 comments
Open

Allow default method implementations in ink! traits #1689

HCastano opened this issue Feb 28, 2023 · 2 comments
Assignees
Labels
A-ink_lang [ink_lang] Work item B-enhancement New feature or request OpenZeppelin

Comments

@HCastano
Copy link
Contributor

There are several limitations which exist around ink!'s traits infrastructure.

One of those is the inability to have default trait method implementations.

Having these would be useful in the context of standards, since a contract could
implement an ink! trait which already has the correct behaviour implemented.

This would also bring traits closer to "normal" Rust traits.

cc @xgreenx

@xgreenx
Copy link
Collaborator

xgreenx commented Mar 19, 2023

This issue requires the refactoring of the trait system first. The main reason is associated output types, mentioned here. Because the default implementation may return something, the output type should be known in the trait definition in the default implementation. So first, to be able to solve this issue, we need to solve the #631 properly. After we have pure Rust traits we can have default methods in the trait definition, but we will face another problem on the #[ink::contract] side, because we will not know the full list of implemented messages(some of them can come from default implementation). But it is possible to solve via introductions of the real and fake messages and the assumption that each trait can't have more than 256 messages.

@DoubleOTheven
Copy link
Contributor

I'm excited for this feature. Please ping me if you need someone to test it out. I think this will unlock the doors to many open source libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_lang [ink_lang] Work item B-enhancement New feature or request OpenZeppelin
Projects
None yet
Development

No branches or pull requests

3 participants