-
Notifications
You must be signed in to change notification settings - Fork 5.4k
AbiDecode for arrays using const_generics
#7008
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
Conversation
218afe8
to
0a62db8
Compare
CodSpeed Performance ReportMerging #7008 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very useful functionality; LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to move the new abi_decode
function to std::codec
now that std
and core
have been merged, but otherwise it looks good.
Do we not need an implementation of AbiEncode
as well?
08bf291
to
2b53ea5
Compare
## Description This is part of #6860. This completes abi encoding for arrays. Allowing arrays of any size as inputs and outputs in predicates/scripts/contracts. This PR also allows arrays to be initialized with "const generics" such as: ```sway #[cfg(experimental_const_generics = true)] impl<T, const N: u64> AbiDecode for [T; N] where T: AbiDecode, { fn abi_decode(ref mut buffer: BufferReader) -> [T; N] { let first: T = buffer.decode::<T>(); let mut array = [first; N]; // <-------------------- This can used now ... array } } ```` ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
Description
This is part of #6860.
This completes abi encoding for arrays. Allowing arrays of any size as inputs and outputs in predicates/scripts/contracts.
This PR also allows arrays to be initialized with "const generics" such as:
Checklist
Breaking*
orNew Feature
labels where relevant.