-
Notifications
You must be signed in to change notification settings - Fork 140
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
Add WrappingNeg trait #153
Conversation
Note that while they do have an inherent |
I thought I had tested for it, but you made me realise where I made a mistake. Thank you!
It did feel a bit odd. And thanks for pointing out #95, it puts things in context. The potential issue with adding WrappingNeg is that Neg was only implemented for Wrapping in Rust 1.10. Wouldn't this create a problem with regards to maintaining compatibility with 1.8? |
I think it will be OK if we follow the style of the others: impl<T: WrappingNeg> WrappingNeg for Wrapping<T>
where
Wrapping<T>: Neg<Output = Wrapping<T>>,
{
fn wrapping_neg(&self) -> Self {
Wrapping(self.0.wrapping_neg())
}
} That |
One thing about this implementation that bugs me a bit is that the
That is good to know, thank you! I didn't see it coming, but turns out the absence of the Neg trait for Wrapping in Rust 1.8 is causing issues for testing though. I guess a workaround would be to use Sub instead ( While it would be great to be able to close this issue, if you feel any |
Since CheckedNeg isn't bound by Neg either, this is fine. I tried to maintain the same order of operations as the Checked traits to make comparisons easier. I also fixed a slight formatting issue. The test for Wrapping falls back on Sub for the time being for lack of a better idea, although it does work for versions including 1.10 and above; I added a FIXME in case Neg becomes available following a MSRV change.
|
Some WrappingNeg tests rely on core::ops::Neg being implemented for core::num::Wrapping<_>. Since it was only added in Rust 1.10, this causes the build to fail for version 1.8 (the MSRV). The problematic tests have been replaced with a TODO. Ideally, if and when the MSRV reaches 1.10, it will be a simple matter of reverting this commit to bring back the tests.
Sorry for the stream-of-thought like nature of the previous comments.
This creates a bit of a problem for the Also, Since Neg was only implemented in 1.10, we can't actually test the Neg op ( Alternatively, if you'd rather tabled implemented WrappingNeg if and when the MSRV reaches 1.10 so both tests can be included, I would understand completely. This legacy business is tricky. So, thank you for your hard work. 🙇♂️ |
I added a little bit to the doc example, but otherwise I think this is good, thanks! bors r+ |
Build succeeded |
Closes #10
A quick search turned up that the extprim implements
PrimInt
for itsu128
andi128
, but, since both have their ownwrapping_neg
method, it's a non-issue.That being said, I don't know for certain that it is the only project that implements
PrimInt
, so it might be wise to wait for a larger version bump before merging this.