如何在具有相同名称的特征之间消除歧义?

时间:2019-07-20 11:54:08

标签: rust substrate parity-io

我正在尝试在运行时中同时使用Assets模块和Balances模块。它们都导出特征T::Balance。当我将资产模块带入我的特征范围时,如下所示:

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

我收到以下错误:

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

1 个答案:

答案 0 :(得分:1)

您无需在这里使用T::Balance,而是需要对Rust编译器更加具体。

您可以执行<T as balances::Trait>::Balance<T as assets::Trait>::Balance来指定您实际要使用的“余额”。

让我知道这是否有帮助!