#Why `Vec<>` requires `&Env`?

4 messages · Page 1 of 1 (latest)

fallow prairie
#

Following doc comments:
https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/src/vec.rs#L77-L80

Values are stored in the environment and are available to contract through the functions defined on Vec. Values stored in the Vec are transmitted to the environment as [Val]s, and when retrieved from the Vec are transmitted back and converted from [Val] back into their type.

Can someone explain me the rationale here?

GitHub

Rust SDK for Soroban Contracts. Contribute to stellar/rs-soroban-sdk development by creating an account on GitHub.

velvet shore
# fallow prairie Following doc comments: https://github.com/stellar/rs-soroban-sdk/blob/main/soro...

Well your contract has limited memory in its environment and calls to allocate memory are fairly expensive (see: https://soroban.stellar.org/docs/fundamentals-and-concepts/rust-dialect#limited-ideally-zero-dynamic-memory-allocation for more info) and therefore the soroban sdk uses no contract side allocation for anything.
As vecs (by their nature) need to allocate memory, they are implemented on the host side (aka. the runtime for the contract) and the contract retrieves and stores these values in the host environment.
The Envis your contracts handle to this environment, therefore you need to pass it to the sdks Vec (and to other types that require dynamic memory allocation, e.g. Bytes)

fallow prairie
#

Alright, another question.
Why is the Vec interface returning something else then original implementation?
https://github.com/stellar/rs-soroban-sdk/blob/main/soroban-sdk/src/vec.rs#L442-L450
How it should be: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.remove

Why is Vec::remove() not returning removed type?

GitHub

Rust SDK for Soroban Contracts. Contribute to stellar/rs-soroban-sdk development by creating an account on GitHub.

solid reef
#

yeah @fallow prairie that seems unnecessarily different. do you mind filing an issue on the sdk repo?