Implementing `Add` for arbitrary trait implementations

Hello,

I have a trait which looks like this,

trait Indicator<In, Out> {
    fn consume(&mut self, data: &Vec<In>) -> Vec<Out>;
}

I want to implement Add for all such indicators, such that if the Out has Add instance it should just add them

But rust keeps cribbing about I cannot implement traits for arbitrary types if not in the same crate

Also, the In parameter for arbitrary Indicator is not constrained. Is there a way to fix that too? Since I can't add PhantomData field for arbitrary Indicator

_

It's probably not possible, but maybe some workarounds are.

Can you alter this guess at what you meant to the actual implementation you wish you had?

impl<T, In, Out> Add<Out> for T
where
    T: Indicator<In, Out>,
    Out: Add<Out, Output=Out>,
{
    type Output = ???;

(It will make suggesting alternatives easier.)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.