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§
Sourcefn then<M: Module<In = Self::Out>>(self, next: M) -> Chain<Self, M>
fn then<M: Module<In = Self::Out>>(self, next: M) -> Chain<Self, M>
Chain this module with another (sequential composition: >>>)
Sourcefn fanout<M: Module<In = Self::In>>(self, other: M) -> Fanout<Self, M>
fn fanout<M: Module<In = Self::In>>(self, other: M) -> Fanout<Self, M>
Split input to two parallel processors (&&&)
Sourcefn feedback<F>(self, combine: F) -> Feedback<Self, F>
fn feedback<F>(self, combine: F) -> Feedback<Self, F>
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.5Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".