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

Match on specific integer values #1012

Closed
wants to merge 1 commit into from

Conversation

tcharding
Copy link
Member

Currently we use Ordering to match precision values against 0. We can
match against the explicit integer values, this saves devs wondering why
we compare to zero, and makes it explicit that there are a discreet
number of valid precision values.

Done as part of the edition 2018 checklist.

Currently we use `Ordering` to match precision values against 0. We can
match against the explicit integer values, this saves devs wondering why
we compare to zero, and makes it explicit that there are a discreet
number of valid precision values.
@@ -384,7 +384,8 @@ fn fmt_satoshi_in(
let opt_precision = options.precision.unwrap_or(0);
trailing_decimal_zeros = opt_precision.saturating_sub(norm_nb_decimals);
},
Ordering::Equal => trailing_decimal_zeros = options.precision.unwrap_or(0),
0 => trailing_decimal_zeros = options.precision.unwrap_or(0),
_ => unreachable!(), // precision() only returns the values above.
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, I'm not a huge fan of adding more panics when we don't need to - I can totally see us forgetting to update this code based on a change to Denomination.

Copy link
Contributor

@dpc dpc May 26, 2022

Choose a reason for hiding this comment

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

True. If all codepaths work fine with any value, listing each value is just asking for trouble in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair points, thanks for the review. I'm going to close this and scratch out the task from the checklist.

@tcharding tcharding closed this May 26, 2022
@tcharding tcharding deleted the 05-26-match-on-ints branch August 5, 2022 02:37
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 this pull request may close these issues.

None yet

3 participants