NEAR Protocol Rust contracts - what's the difference between near-sdk-rs data structures and std ones?

257 views Asked by At

In Rust we have many data structures available in the standard library. NEAR Protocol has some optimized data structures in near-api-rs, but what are the main differences?

1

There are 1 answers

0
mattdlockyer On

Evgeny Kuzyakov (a Near protocol engineer) answered in Discord:

If you talking about LookupMap vs HashMap then the difference is LookupMap is stored in the trie, while HashMap is stored in memory.

When a method on a contract is called, the contract reads and deserializes the main struct from the storage trie. If it contains a HashMap then all records of this map will be read and deserialized. If it contains a LookupMap then only the key_prefix will be read and deserialized, so it's cheaper from gas perspective. But every time you access a key/value from a LookupMap you have to read and deserialize it from the trie.