-
Notifications
You must be signed in to change notification settings - Fork 144
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 trait for signed to unsigned conversion #391
Comments
I'm open to it. There's a similar request in rust-num/num-traits#163.
The way you've written the trait will always get you where
T: ToUnsigned + Integer,
<T as ToUnsigned>::UnsignedType: Integer, You might try to make a wrapper trait: pub trait ToUnsignedInteger: ToUnsigned + Integer
where
<Self as ToUnsigned>::UnsignedType: Integer
{} But I think that added constraint will have limited use do to rust-lang/rust#20671. |
One snag with the trait definitions in my OP: they panic when given |
I would like a trait such as
Ideally, I would like the traits to "bubble" across the UnsignedType. For example, if my function accepts a
T: ToUnsigned + Integer
, then I would ideally want to be able to call.abs_unsigned()
onT
and get back something implementing bothUnsigned
andInteger
.The text was updated successfully, but these errors were encountered: