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

All bit twiddling functions in num::traits::PrimInt should take or return usize instead of u32 #14

Closed
cuviper opened this issue Dec 19, 2017 · 4 comments

Comments

@cuviper
Copy link
Member

cuviper commented Dec 19, 2017

From @octurion on April 10, 2015 10:12

The trait num::traits::PrimInt mandates that any type implementing it must also implement Shl<usize, Output=Self> and Shr<usize, Output=Self> (in other words, PrimInt mandates that the shift amount be of type usize).

Thus all bit twiddling functions (trailing_zeros, rotate_left, count_zeros etc.) in PrimInt should take or return a usize instead of u32 as the number of bits for the sake of consistency with what the implementation restrictions on Shl and Shr mandate.

Copied from original issue: rust-num/num#80

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

From @gnzlbg on December 17, 2015 12:27

The problem is that the methods on primitive types like rotate_left expect an u32 and that cannot be changed anymore (that ship has sailed).

Maybe it would be better to require Shl<u32, Output=Self> and Shr<u32, Output=Self> instead. What do you think?

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

From @gnzlbg on December 17, 2015 15:49

I've implemented this and some other bit wise algorithms in PrimInt.

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

I think changing the trait bounds to u32 sounds fine, but it will be a breaking change, which I want to be pretty conservative about. I should start a list somewhere of "things to break" so we can plan to do them all at once.

@cuviper
Copy link
Member Author

cuviper commented Mar 5, 2018

I've decided to limit the clutter of breaking change issues, so they will now be tracked collectively in #47. I'm closing this issue for now as postponed but we can still discuss its merits here as needed.

@cuviper cuviper closed this as completed Mar 5, 2018
@cuviper cuviper removed this from the num-traits-0.x milestone Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant