You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pubtraitToUnsigned{typeUnsignedType:Unsigned;fnabs_unsigned(&self) -> Self::UnsignedType;}// Example for i32implToUnsignedfori32{typeUnsignedType = u32;fnabs_unsigned(&self) -> Self::UnsignedType{self.abs()asSelf::UnsignedType}}// Example for u32implToUnsignedforu32{typeUnsignedType = u32;fnabs_unsigned(&self) -> Self::UnsignedType{*self}}
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() on T and get back something implementing both Unsigned and Integer.
The text was updated successfully, but these errors were encountered:
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() on T and get back something implementing both Unsigned and Integer.
The way you've written the trait will always get you Unsigned, but I don't think it's possible to express the conditional part in an automatic way. You can manually write that like:
where
T:ToUnsigned + Integer,
<TasToUnsigned>::UnsignedType:Integer,
One snag with the trait definitions in my OP: they panic when given std::i32::MIN since it is not possible to call .abs() on that value. The actual trait implementations should handle this case.
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: