ink icon indicating copy to clipboard operation
ink copied to clipboard

Why trait defintions don't support generic

Open yjhmelody opened this issue 4 years ago • 5 comments

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>);
}

yjhmelody avatar Mar 17 '21 03:03 yjhmelody

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.

Robbepop avatar Mar 17 '21 10:03 Robbepop

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?

atenjin avatar Mar 18 '21 03:03 atenjin

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

HCastano avatar Jun 14 '21 20:06 HCastano

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 avatar Jun 16 '21 09:06 Robbepop

This is going to be fixed in https://github.com/paritytech/ink/pull/665 where all ink! trait definitions are generic over an ink! contract environment.

Robbepop avatar Sep 22 '21 09:09 Robbepop

The issue has been fixed by #665

SkymanOne avatar Apr 12 '23 19:04 SkymanOne