pub struct Apply<F, A, B> where
    F: FnMut(&A) -> B + Send + 'static,
    A: Send + 'static,
    B: Send + 'static, 
{ /* private fields */ }
Expand description

Applies a function to each sample in the stream.

Inputs

in: Input

Outputs

out: Output after 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

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more