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

feat(gprimitives): add NonZeroU256 type & lossy conversion for H160 #4012

Merged
merged 23 commits into from
Jun 25, 2024

Conversation

vobradovich
Copy link
Member

@vobradovich vobradovich commented Jun 14, 2024

Resolves #3973
Resolves #4020
Resolves #4031

Related to gear-tech/sails#285

@vobradovich vobradovich self-assigned this Jun 14, 2024
@vobradovich vobradovich added A0-pleasereview PR is ready to be reviewed by the team A2-mergeoncegreen PR is ready to merge after CI passes labels Jun 14, 2024
@vobradovich vobradovich marked this pull request as ready for review June 14, 2024 13:02
gprimitives/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@StackOverflowExcept1on StackOverflowExcept1on left a comment

Choose a reason for hiding this comment

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

Where is the implementation of addition, subtraction and other operations for NonZeroU256? Similar to https://docs.rs/primitive-types/latest/primitive_types/struct.U256.html#trait-implementations

@StackOverflowExcept1on StackOverflowExcept1on changed the title feat(gprimitives): implement NonZeroU256 type feat(gprimitives): add NonZeroU256 type & lossy conversion for H160 Jun 23, 2024
@vobradovich
Copy link
Member Author

Where is the implementation of addition, subtraction and other operations for NonZeroU256? Similar to https://docs.rs/primitive-types/latest/primitive_types/struct.U256.html#trait-implementations

Hi! added implementation of add, sub, mul, pow
The original task from @breathx and @DennisInSky was to

  • choose what you need)
  • you can further expand / suppport as much as you like

Overall, this is a temporary solution until generic NonZero<> stabilizes.

@StackOverflowExcept1on
Copy link
Member

LGTM!

Overall, this is a temporary solution until generic NonZero<> stabilizes

NonZero<T> is already stabilized in 1.79, but it seems to me that we can't implement ZeroablePrimitive trait to make it sound safe

@vobradovich
Copy link
Member Author

is already stabilized in 1.79

yeah, missed it, looked it when it was 1.78)
so, waiting for ZeroablePrimitive to be implemented for U256

Copy link
Member

@breathx breathx left a comment

Choose a reason for hiding this comment

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

Basically, I'm okay with this impl, but for me it looks a bit like overengineering, so could be merged as is but then simplified in many places

gprimitives/src/lib.rs Outdated Show resolved Hide resolved
gprimitives/src/lib.rs Show resolved Hide resolved
gprimitives/src/nonzero_u256.rs Show resolved Hide resolved
gprimitives/src/nonzero_u256.rs Outdated Show resolved Hide resolved
gprimitives/src/nonzero_u256.rs Show resolved Hide resolved
@StackOverflowExcept1on StackOverflowExcept1on merged commit bcfaff1 into master Jun 25, 2024
10 checks passed
@StackOverflowExcept1on StackOverflowExcept1on deleted the vo/gprimitives_nonzero_u256 branch June 25, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-pleasereview PR is ready to be reviewed by the team A2-mergeoncegreen PR is ready to merge after CI passes
Projects
None yet
4 participants