How to avoid code duplication with regards to composition (since inheritance is not available)?

40 points synthguitar

I am writing a bunch of dsp stuff. Filters mainly for now.

So I have Fir, IIr and I have created moving sum and moving average etc.

The moving average and moving sum filters use the Fir filter underneath. There is not a ton of boilerplate but I basically sit and write or rather copy paste the same forwarding functions again and again.

The only thing that differ is the constructor.

Is there some way around it?

pub fn new(order : u16) -> MovingSum<T>
{
    MovingSum
    {
        filter: Fir::<T>::new(vec![T::from(1 as u16); order as usize])
    }
}
\t
pub fn order(&self) -> usize
{
    self.filter.order()
}

pub fn step(&mut self, x : T) -> T
{
    self.filter.step(x)
}