【问题标题】:How to instantiate a vector of near protocol?如何实例化近协议向量?
【发布时间】:2020-09-26 07:48:28
【问题描述】:

如何实例化一个向量?什么是 id,为什么需要它,它应该具有什么属性?

pub fn new(id: Vec<u8>) -> Self 创建零元素的新向量。使用 id 作为 trie 上的唯一标识符。 https://docs.rs/near-sdk/0.10.0/near_sdk/collections/struct.Vector.html

报错:

let id = account_id.into_bytes();
let mut products_list = Vector::new(id);
   |             -----------------   ^^^^^^^^^^^ cannot infer type for type parameter `T`

【问题讨论】:

    标签: rust nearprotocol


    【解决方案1】:

    发布的代码无法推断泛型Vector<T> 类型中的类型参数T 的类型。您必须为products_list 提供类型注释,以便编译器知道完整的类型(参见data types)。

    【讨论】:

    • 准确地说,这里有一个例子:let mut products_list: Vector<String> = Vector::new(b"something".to_vec());products_list.push(&"aloha".to_string());
    猜你喜欢
    • 1970-01-01
    • 2022-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多