-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 From<T> for Wrapping<T> and From<Wrapping<T>> for T #44937
Comments
It doesn't explicitly list |
Can you point to an example of real code where these impls would be useful? |
Any real code that uses As a personal example, I dabbled with writing a Game Boy Advance emulator a while back; |
Sure, I agree that |
I am going to close this for now. I would be happy to consider an RFC if someone finds concrete use cases that would benefit from |
I guess for me this was more of an initial impression sort of thing. Using I think part of the problem was that when interacting with the standard library, syntax like |
Making porting any RNG not the worst experience ever, for starters. Or something like cyclic redundancy checks, which assumes twos-complement arithmetic and depends on a memoized array of coefficients. Basically any code where placing |
@myconix could you link to real code? |
https://github.com/libtom/libtomcrypt/blob/develop/src/hashes/md5.c for a less trivial example |
I am trying to see concretely what improvement there would be. |
Right now, Wrapping doesn't allow for operating with plain integers, even literals, That, combined with the fact that there's no succinct way to specify a Wrapping literal, means that EVERY integer literal in those code snippets would need a |
@myconix could you demonstrate a snippet of code ported from any one of those links into Rust,
|
I can't do that in a reasonable time frame. The quicker explanation is that they can all be reduced to:
Giving an error at compile time. To get this to work, you need to explicitly make the 4 wrapping as well:
This is a trivial example, but if I wanted to implement one of those examples in Rust, this problem gets worse proportional to the number of ops in the code. |
@myconix I am going to continue to insist on seeing:
because I really don't believe that adding these impls would improve the use cases you are writing about. I've locked the thread because I don't see the discussion here moving in a productive direction, but I would be willing to consider an RFC (however brief) that lays out concrete advantages of If anyone is interested in spearheading an RFC, make sure to include:
|
It would be nice if
std::num::Wrapping
supportedFrom<T>
andInto<T>
, at least whenT
is a numeric primitive. I assumed these impls would exist and was surprised to find that they do not.The text was updated successfully, but these errors were encountered: