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
I am working on a project using uom for quantity and unit aware numeric types.
I have a piece of code that should abstract over Length and Angle and requires the Signed trait from num-traits. However, uom is unable to implement the Signed trait since it requires Num which requires NumOps which requires Mul<Self, Self>. Implementing Mul<Self, Self> for Length is incorrect since the quantity changes to Area.
pub trait Signed: Sized + Num + Neg<Output = Self>
I would argue the trait bounds on Signed are currently too restrictive. We can work around the problem by defining our own traits but we would rather see this addressed at the root, improving the Rust ecosystem.
It's not something we can immediately change to affect the whole ecosystem -- that would be a breaking change that everyone would have to adapt to.
One thing you could possibly do is create your own Signed and blanket impl from num_traits:
impl<T: num_traits::Signed>SignedforT{// your version of methods}
... and then add additional impl types as needed. However, those extra types must be in the same crate as your Signed definition, so the compiler knows for coherence that they will never add num_traits::Signed and cause overlap.
I am working on a project using
uom
for quantity and unit aware numeric types.I have a piece of code that should abstract over
Length
andAngle
and requires theSigned
trait fromnum-traits
. However,uom
is unable to implement theSigned
trait since it requiresNum
which requiresNumOps
which requiresMul<Self, Self>
. ImplementingMul<Self, Self>
forLength
is incorrect since the quantity changes toArea
.I would argue the trait bounds on
Signed
are currently too restrictive. We can work around the problem by defining our own traits but we would rather see this addressed at the root, improving the Rust ecosystem.For the full discussion, see iliekturtles/uom#273
The text was updated successfully, but these errors were encountered: