Amiya Behera
Amiya Behera

Reputation: 2270

How to instantiate a vector of near protocol?

How to instantiate a vector? What is an id, why it's needed, and what property it should have?

pub fn new(id: Vec<u8>) -> Self Create new vector with zero elements. Use id as a unique identifier on the trie. https://docs.rs/near-sdk/0.10.0/near_sdk/collections/struct.Vector.html

It gives error:

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

Upvotes: 0

Views: 155

Answers (1)

IInspectable
IInspectable

Reputation: 51420

The code posted cannot infer the type of type parameter T in the generic Vector<T> type. You are going to have to provide a type annotation for products_list, so that the compiler knows the complete type (see data types).

Upvotes: 1

Related Questions