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

Make Uint128 inner value private #905

Closed
webmaster128 opened this issue Apr 28, 2021 · 3 comments · Fixed by #946
Closed

Make Uint128 inner value private #905

webmaster128 opened this issue Apr 28, 2021 · 3 comments · Fixed by #946
Assignees
Milestone

Comments

@webmaster128
Copy link
Member

No description provided.

@webmaster128 webmaster128 added this to the 1.0.0 milestone Apr 28, 2021
@webmaster128 webmaster128 modified the milestones: 1.0.0, 0.15.0 May 16, 2021
@ethanfrey
Copy link
Member

This will break a lot of code.

In particular, if I want to use Uint128 in a match, I cannot do:

match amount {
  Uint128::zero() => do_something(),
  _ => do_something_else(),
}

As you cannot use functions in the branches of match. Maybe this works with const fn? In any case, if you deprecate Uint128(0), please ensure there is a replacement for the above idiom (which I used twice today)

@webmaster128
Copy link
Member Author

We have a getter method to get the inner value: a.u128() which can be used everywhere when you need the primary type. Then the code above becomes:

match amount.u128() {
  0 => do_something(),
  1..=234 => do_something_else(),
  _ => do_something_else_else(),
}

@ethanfrey
Copy link
Member

Hmmm... I guess this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants