Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to add equivalent of the Vec type #1077

Closed
emilyaherbert opened this issue Feb 22, 2022 · 5 comments · Fixed by #1118
Closed

Proposal to add equivalent of the Vec type #1077

emilyaherbert opened this issue Feb 22, 2022 · 5 comments · Fixed by #1118
Labels
enhancement New feature or request lib: std Standard library

Comments

@emilyaherbert
Copy link
Contributor

When writing Sway code I have been finding myself wanting the Vec type, it would be awesome if we had it 😄

Dependent on this issue (#428) and on dynamic size arrays

Rust's implemenation of Vec: https://doc.rust-lang.org/std/vec/struct.Vec.html

@adlerjohn adlerjohn transferred this issue from FuelLabs/sway-lib-std Mar 29, 2022
@adlerjohn adlerjohn added enhancement New feature or request lib: std Standard library labels Mar 29, 2022
@adlerjohn adlerjohn mentioned this issue Mar 31, 2022
3 tasks
@AlicanC
Copy link
Contributor

AlicanC commented May 27, 2022

How would this be represented in the ABI and coded?

From the impl at #1118:

struct RawVec<T> {
    ptr: u64,
    cap: u64,
}
pub struct Vec<T> {
    buf: RawVec,
    len: u64,
}

This would be coded like (ptr: u64, cap: u64, len: u64) which lacks the actual data.

@otrho
Copy link
Contributor

otrho commented May 27, 2022

Do we plan to send heap oriented data across the FFI? This will be very tricky, fairly brittle IMO, easy to get wrong, other than for raw pointers to individual heap allocations.

@AlicanC
Copy link
Contributor

AlicanC commented May 27, 2022

I have to send data from the heap in my Multicall script which was the reason for mem::Buffer. Currently the MC script has a fixed-length section that can be represented in the ABI (and can be coded with our AbiCoder) and a dynamic-length part managed with a Buffer.

@adlerjohn
Copy link
Contributor

Yes, we plan to support heap types across the ABI. The SDKs will have to be smart enough to know about particular heap types and set their pointers correctly. The data can be somewhere in scriptData, it doesn't have to be on the actual heap.

@mohammadfawaz
Copy link
Contributor

TIL! But yeah that makes sense.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lib: std Standard library
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants