Search code examples
rustsubstrateparity-io

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;
    |                                          ^^^^^^^^^^


Solution

  • 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!