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 #80

Closed
octurion opened this issue Apr 10, 2015 · 4 comments

Comments

@octurion
Copy link

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.

@gnzlbg
Copy link

gnzlbg commented Dec 17, 2015

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?

@gnzlbg
Copy link

gnzlbg commented Dec 17, 2015

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

@cuviper
Copy link
Member

cuviper commented Dec 17, 2015

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

cuviper commented Dec 19, 2017

This issue was moved to rust-num/num-traits#14

@cuviper cuviper closed this as completed Dec 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants