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

Extend primitive conversions and implement TryFrom trait for integer values #5127

Merged
merged 15 commits into from
Sep 23, 2023

Conversation

bitzoic
Copy link
Member

@bitzoic bitzoic commented Sep 19, 2023

Description

There have been a number of requests to convert between integer values. This is especially important in some of the recently introduced standards and changes made in the storage optimizations.

This PR extends the primitive conversions to extend values and also implements the TryFrom trait for u64, u32, u16, and u8.

Note: The TryFrom implementations are not included in the prelude and must be imported. The primitive conversions do not need to be imported as they are included in the core.

Checklist

  • I have linked to any relevant issues.
  • 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).
  • 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.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@bitzoic bitzoic added enhancement New feature or request lib: std Standard library labels Sep 19, 2023
@bitzoic bitzoic requested review from xunilrj, IGI-111 and a team September 19, 2023 13:41
@bitzoic bitzoic self-assigned this Sep 19, 2023
SwayStar123
SwayStar123 previously approved these changes Sep 19, 2023
sway-lib-std/src/u16.sw Outdated Show resolved Hide resolved
sway-lib-std/src/u16.sw Outdated Show resolved Hide resolved
Copy link
Member

@SwayStar123 SwayStar123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good otherwise. Just remove all the _u64 and .into_u64() for the as_b256 functions and then move them into the same impl block

sway-lib-core/src/primitive_conversions.sw Show resolved Hide resolved
SwayStar123
SwayStar123 previously approved these changes Sep 21, 2023
@bitzoic bitzoic requested a review from a team September 21, 2023 11:42
Copy link
Contributor

@Braqzen Braqzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have try_as_uX methods and some TryFrom impls? Can we not only use the latter?

@bitzoic
Copy link
Member Author

bitzoic commented Sep 21, 2023

Why do we have try_as_uX methods and some TryFrom impls? Can we not only use the latter?

These exist prior to the PR in the primitive_conversion.sw file. They will be replaced with TryInto once the trait exists.

@bitzoic bitzoic requested a review from a team September 22, 2023 08:29
@bitzoic bitzoic added the breaking May cause existing user code to break. Requires a minor or major release. label Sep 22, 2023
Copy link
Contributor

@Braqzen Braqzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@bitzoic bitzoic enabled auto-merge (squash) September 23, 2023 07:34
@bitzoic bitzoic merged commit ff5ce9d into master Sep 23, 2023
27 checks passed
@bitzoic bitzoic deleted the bitzoic-conversions branch September 23, 2023 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking May cause existing user code to break. Requires a minor or major release. enhancement New feature or request lib: std Standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants