代码之家  ›  专栏  ›  技术社区  ›  Tyrese Tiger

如何解决Rust区块链智能合约中的'[E0277]:类型'[BBalance]'无法通过'String'错误进行索引?

  •  0
  • Tyrese Tiger  · 技术社区  · 1 年前

    我正在用铁锈写calculate_balance_changes函数。 但也有一些错误:

    error[E0277]: the type `[Balance]` cannot be indexed by `String`
    --> src/main.rs:126:30
        |
    126 |                 new_balances[input.address].coins.push(Coin {
        |                              ^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
        |
    = help: the trait `SliceIndex<[Balance]>` is not implemented for `String`
    = note: required for `Vec<Balance>` to implement `Index<String>`
    
    error[E0277]: the type `[Balance]` cannot be indexed by `String`
    --> src/main.rs:138:26
        |
    138 |             new_balances[definition.issuer].coins.push(Coin {
        |                          ^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
        |
    = help: the trait `SliceIndex<[Balance]>` is not implemented for `String`
    = note: required for `Vec<Balance>` to implement `Index<String>`
    
    error[E0277]: the type `[Balance]` cannot be indexed by `String`
    --> src/main.rs:149:34
        |
    149 |             if original_balances[input.address].coins
        |                                  ^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
        |
    = help: the trait `SliceIndex<[Balance]>` is not implemented for `String`
    = note: required for `Vec<Balance>` to implement `Index<String>`
    
    For more information about this error, try `rustc --explain E0277`.
    warning: `rust-task` (bin "rust-task") generated 1 warning
    error: could not compile `rust-task` due to 3 previous errors; 1 warning emitted
    

    计算余额变化。

    0 回复  |  直到 1 年前