Open
Description
I would like a trait such as
pub trait ToUnsigned {
type UnsignedType: Unsigned;
fn abs_unsigned(&self) -> Self::UnsignedType;
}
// Example for i32
impl ToUnsigned for i32 {
type UnsignedType = u32;
fn abs_unsigned(&self) -> Self::UnsignedType {
self.abs() as Self::UnsignedType
}
}
// Example for u32
impl ToUnsigned for u32 {
type UnsignedType = u32;
fn abs_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
.
Metadata
Metadata
Assignees
Labels
No labels