No, there are no features covering this functionality. Only some throws are possible, and a complete list can be found in The Book .
As for your implementation of Add , you should modify it as follows so that it works:
use std::ops::Add; struct Test<T: Add>{ m: T } impl<T> Add for Test<T> where T: Add<Output = T> { type Output = Self; fn add(self, rhs: Self) -> Self { Test { m: self.m + rhs.m } } }
You can find a good explanation why an additional T: Add<Output = T> binding T: Add<Output = T> needed in this SO answer . This may be even closer to your specific case.
ljedrz
source share