The code below should be pretty self-explanatory: a Scalar is a plain old number, and Scalar.exp should return another Scalar, possibly of a different type than the Scalar it was called on.
pub trait Scalar:
ToString +
Add + AddAssign +
Sub + SubAssign +
Mul + MulAssign +
Div + DivAssign +
Neg + Rem +
PartialEq + PartialOrd
{
fn exp(&self) -> Box<dyn Scalar>;
}
This doesn't work, since one of the subtraits of Scalar requires Sized, and thus Scalar can't be a trait object.
How should I do what I'm trying to do here? I need a trait object that guarantees the subtraits listed above, but I don't think I can make one directly.