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

Why trait defintions don't support generic #737

Closed
yjhmelody opened this issue Mar 17, 2021 · 6 comments
Closed

Why trait defintions don't support generic #737

yjhmelody opened this issue Mar 17, 2021 · 6 comments
Labels
B-feature-request A request for a new feature. C-question Further information is requested

Comments

@yjhmelody
Copy link
Contributor

I find trait cannot be generic

        if !item_trait.generics.params.is_empty() {
            return Err(format_err_spanned!(
                item_trait.generics.params,
                "ink! trait definitions must not be generic"
            ))
        }

But I want to define environment-independent traits, such as:

#[ink::trait_definition]
pub trait Ownable<E: Environment> {
    /// Initializes the contract setting the deployer as the initial owner.
    #[ink(constructor)]
    fn new() -> Self;

    /// Returns the account id of the current owner.
    #[ink(message)]
    fn owner(&self) -> Option<E::AccountId>;

    /// Transfer ownership to new owner.
    #[ink(message)]
    fn transfer_ownership(&mut self, new_owner: Option<E::AccountId>);
}
@Robbepop
Copy link
Collaborator

We are currently working to make ink! trait definitions really usable and afterwards this feature is going to be very important in my opinion. The ability to define ink! traits environment agnostic is not MVP but really needed.

@atenjin
Copy link

atenjin commented Mar 18, 2021

Hi @Robbepop

Yes @yjhmelody is our guy who is working for Ask! Same to ink!, we need to design interface or something else for supporting designing specification. And for now, we think ink! trait_definitions can not cover many scenes, just like this issue #683 (in fact the scenes listed in this issue are also incomplete)

and in your pr #665, It seems that it can't solve many cases either. Thus, is there existed a formal issue or discussions or channal to discuss the design for trait_definitions?

@HCastano
Copy link
Contributor

@Robbepop We might want to have a separate issue for discussions and designing generics - I can't find anything in the issue tracker

@Robbepop
Copy link
Collaborator

Let us first get non-generic traits right and then we can tackle making them generic or adding similar features that will help with library-like smart contracts that are urgently needed.

@Robbepop
Copy link
Collaborator

This is going to be fixed in #665 where all ink! trait definitions are generic over an ink! contract environment.

@SkymanOne
Copy link
Contributor

The issue has been fixed by #665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-feature-request A request for a new feature. C-question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants