Skip to main content

ModuleExt

Trait ModuleExt 

Source
pub trait ModuleExt: Module + Sized {
    // Provided methods
    fn then<M: Module<In = Self::Out>>(self, next: M) -> Chain<Self, M> { ... }
    fn parallel<M: Module>(self, other: M) -> Parallel<Self, M> { ... }
    fn fanout<M: Module<In = Self::In>>(self, other: M) -> Fanout<Self, M>
       where Self::In: Clone { ... }
    fn map<F, U>(self, f: F) -> Map<Self, F>
       where F: Fn(Self::Out) -> U { ... }
    fn contramap<F, U>(self, f: F) -> Contramap<Self, F, U>
       where F: Fn(U) -> Self::In { ... }
    fn feedback<F>(self, combine: F) -> Feedback<Self, F>
       where Self::Out: Default + Clone { ... }
    fn first<C>(self) -> First<Self, C> { ... }
    fn second<C>(self) -> Second<Self, C> { ... }
}
Expand description

Extension trait providing combinator methods for all modules

Provided Methods§

Source

fn then<M: Module<In = Self::Out>>(self, next: M) -> Chain<Self, M>

Chain this module with another (sequential composition: >>>)

Source

fn parallel<M: Module>(self, other: M) -> Parallel<Self, M>

Run two modules in parallel (***)

Source

fn fanout<M: Module<In = Self::In>>(self, other: M) -> Fanout<Self, M>
where Self::In: Clone,

Split input to two parallel processors (&&&)

Source

fn map<F, U>(self, f: F) -> Map<Self, F>
where F: Fn(Self::Out) -> U,

Transform output with a pure function

Source

fn contramap<F, U>(self, f: F) -> Contramap<Self, F, U>
where F: Fn(U) -> Self::In,

Transform input with a pure function

Source

fn feedback<F>(self, combine: F) -> Feedback<Self, F>
where Self::Out: Default + Clone,

Create a feedback loop with a single-sample unit delay.

The combine closure is called as combine(external_input, previous_output):

  • the first argument is this tick’s external input,
  • the second argument is the module’s output from the previous tick, delayed by exactly one sample for causality.

On the very first tick (and after reset), the previous-output argument is Self::Out::default() (i.e. 0.0 for f64). The combined value is fed to the wrapped module, and its output is both returned and stored as the next tick’s feedback signal.

§Example: a one-pole low-pass via feedback
use quiver::combinator::{Identity, Module, ModuleExt};

let coeff = 0.5;
// y[n] = input * (1 - coeff) + previous_output * coeff
let mut one_pole = Identity::<f64>::new()
    .feedback(move |input, previous| input * (1.0 - coeff) + previous * coeff);

// First tick: previous_output defaults to 0.0.
assert!((one_pole.tick(1.0) - 0.5).abs() < 1e-12); // 1*0.5 + 0*0.5
// Second tick: previous_output is now 0.5.
assert!((one_pole.tick(1.0) - 0.75).abs() < 1e-12); // 1*0.5 + 0.5*0.5
Source

fn first<C>(self) -> First<Self, C>

Apply this module only to the first element of a tuple

Source

fn second<C>(self) -> Second<Self, C>

Apply this module only to the second element of a tuple

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<M: Module> ModuleExt for M