pub struct Apply<F, A, B>where
F: FnMut(&A) -> B + Send + 'static,
A: Send + 'static,
B: Send + 'static,{ /* private fields */ }
Expand description
Apply a function to each sample.
Stream Inputs
in
: Input
Stream Outputs
out
: Output, corresponding to input with function applied
Usage
use futuresdr::blocks::Apply;
use futuresdr::runtime::Flowgraph;
use num_complex::Complex;
let mut fg = Flowgraph::new();
// Double each sample
let doubler = fg.add_block(Apply::new(|i: &f32| i * 2.0));
// Note that the closure can also hold state
let mut last_value = 0.0;
let moving_average = fg.add_block(Apply::new(move |i: &f32| {
let new_value = (last_value + i) / 2.0;
last_value = *i;
new_value
}));
// Additionally, the closure can change the type of the sample
let to_complex = fg.add_block(Apply::new(|i: &f32| {
Complex {
re: 0.0,
im: *i,
}
}));
Implementations§
Auto Trait Implementations§
impl<F, A, B> RefUnwindSafe for Apply<F, A, B>where A: RefUnwindSafe, B: RefUnwindSafe, F: RefUnwindSafe,
impl<F, A, B> Send for Apply<F, A, B>
impl<F, A, B> Sync for Apply<F, A, B>where A: Sync, B: Sync, F: Sync,
impl<F, A, B> Unpin for Apply<F, A, B>where A: Unpin, B: Unpin, F: Unpin,
impl<F, A, B> UnwindSafe for Apply<F, A, B>where A: UnwindSafe, B: UnwindSafe, F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more