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

Implement Sub/SubAssign for all Uint* types #1242

Merged
merged 2 commits into from
Mar 16, 2022
Merged

Conversation

webmaster128
Copy link
Member

For #1186

@webmaster128 webmaster128 mentioned this pull request Mar 14, 2022
11 tasks
Copy link
Contributor

@ueco-jb ueco-jb left a comment

Choose a reason for hiding this comment

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

LGTM
My only suggestion - maybe .expect could include both numbers in message.
Plenty of times I stumbled upon some "anonymous" errors and had a lot of issues finding out which operation exactly failed - providing actual numbers might give some context.
Opinions?

Comment on lines +55 to +58
impl AllImpl<'_> for Uint64 {}
impl AllImpl<'_> for Uint128 {}
impl AllImpl<'_> for Uint256 {}
impl AllImpl<'_> for Uint512 {}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@webmaster128
Copy link
Member Author

My only suggestion - maybe .expect could include both numbers in message.
Plenty of times I stumbled upon some "anonymous" errors and had a lot of issues finding out which operation exactly > failed - providing actual numbers might give some context.
Opinions?

You mean adding a debug message to assert_eq!? I think this creates a lot of overhead in the test code that is easy to get wrong when copy/pasting. Usually you can find the failing test by file and line number.

I would do this in cases where we loop over test data where the line alone does not tell you exactly which test is failing. But we don't have this often.

Uint64(
self.u64()
.checked_sub(rhs.u64())
.expect("attempt to subtract with overflow"),
Copy link
Contributor

@ueco-jb ueco-jb Mar 16, 2022

Choose a reason for hiding this comment

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

No no, I meant strictly cases like here - but I just realized, that .expect takes &str as an argument.
So we can't do, for example, format!() here to create some nice String with local variables (at least not cheap - without any copy etc).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good point. Yeah, this is pretty inconsistent anyways. Sometimes we just .unwrap(), sometimes we create out own message. Let's keep this in mind and address it separately.

@webmaster128 webmaster128 merged commit 0a1ba39 into main Mar 16, 2022
@webmaster128 webmaster128 deleted the implement-sub branch March 16, 2022 09:05
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.

2 participants