简体   繁体   中英

How to disambiguate between traits with the same name?

I am trying to use both the Assets module and Balances module in my runtime. They both export the Trait T::Balance . When I bring the Assets module in scope of my trait like so:

pub trait Trait: assets::Trait + balances::Trait {}

I get the following error:

error[E0221]: ambiguous associated type `Balance` in bounds of `T`
   --> /home/volt/workspaces/lsaether/vyzer/runtime/src/markets.rs:124:42
    |
124 |         ValidityBond get(validity_bond): T::Balance;
    |                                          ^^^^^^^^^^ ambiguous associated type `Balance`
    |
note: associated type `T` could derive from `srml_assets::Trait`
   --> /home/volt/workspaces/lsaether/vyzer/runtime/src/markets.rs:124:42
    |
124 |         ValidityBond get(validity_bond): T::Balance;
    |                                          ^^^^^^^^^^
note: associated type `T` could derive from `srml_balances::Trait`
   --> /home/volt/workspaces/lsaether/vyzer/runtime/src/markets.rs:124:42
    |
124 |         ValidityBond get(validity_bond): T::Balance;
    |                                          ^^^^^^^^^^

Rather than use T::Balance here, you need to be more specific for the Rust compiler.

You can do <T as balances::Trait>::Balance or <T as assets::Trait>::Balance to specify which "Balance" you actually want to use.

Let me know if this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM