InspectFn

Trait InspectFn 

Source
pub trait InspectFn<I, T>: Send + 'static
where T: ?Sized,
{ // Required method fn execute(&self, id: &I, data: &T) -> Result; }
Expand description

Inspect function.

This trait defines a function that can be used to inspect borrowed data in a stream without modifying it, and is not expected to return new data.

There’s a range of different implementations of this trait, allowing you to use a variety of function shapes, including support for Splat, as well as support for the [WithId] and [WithSplat] adapters. Furthermore, the trait can be implemented for custom types to add new behaviors. Note that all implementations also allow to return a Report, which makes it possible to return diagnostics from the function execution.

The 'static lifetimes is mandatory as closures must be moved into actions, so requiring it here allows us to reduce the verbosity of trait bounds.

§Examples

Inspect data:

use zrx_stream::function::InspectFn;

// Define and execute function
let f = |&n: &i32| println!("{n}");
f.execute(&"id", &42)?;

Inspect data with splat argument:

use zrx_stream::function::{InspectFn, Splat};

// Define and execute function
let f = |&a: &i32, &b: &i32| println!("{a} < {b}");
f.execute(&"id", Splat::from_ref(&(1, 2)))?;

Required Methods§

Source

fn execute(&self, id: &I, data: &T) -> Result

Executes the inspect function.

§Errors

This method returns an error if the function fails to execute.

Implementors§

Source§

impl<F, R, I, T1> InspectFn<I, Splat<(T1,)>> for F
where F: Fn(&T1) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T1, T2> InspectFn<I, Splat<(T1, T2)>> for F
where F: Fn(&T1, &T2) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T1, T2, T3> InspectFn<I, Splat<(T1, T2, T3)>> for F
where F: Fn(&T1, &T2, &T3) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4> InspectFn<I, Splat<(T1, T2, T3, T4)>> for F
where F: Fn(&T1, &T2, &T3, &T4) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, T5> InspectFn<I, Splat<(T1, T2, T3, T4, T5)>> for F
where F: Fn(&T1, &T2, &T3, &T4, &T5) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, T5, T6> InspectFn<I, Splat<(T1, T2, T3, T4, T5, T6)>> for F
where F: Fn(&T1, &T2, &T3, &T4, &T5, &T6) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, T5, T6, T7> InspectFn<I, Splat<(T1, T2, T3, T4, T5, T6, T7)>> for F
where F: Fn(&T1, &T2, &T3, &T4, &T5, &T6, &T7) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T1, T2, T3, T4, T5, T6, T7, T8> InspectFn<I, Splat<(T1, T2, T3, T4, T5, T6, T7, T8)>> for F
where F: Fn(&T1, &T2, &T3, &T4, &T5, &T6, &T7, &T8) -> R + Send + 'static, R: IntoReport, I: Display,

Source§

impl<F, R, I, T> InspectFn<I, T> for F
where F: Fn(&T) -> R + Send + 'static, R: IntoReport, I: Display, T: Value + ?Sized,