Skip to content

Why trait defintions don't support generic #737

Closed
@yjhmelody

Description

@yjhmelody

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-feature-requestA request for a new feature.C-questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions