LiftFn

Trait LiftFn 

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

Lift function.

This trait defines a function that transforms data of type T into a vector of items of type U, which creates a vector of nested items, allowing us to implement higher-order collections and relationships to manage data-centric interdependencies. Transformations are expected to be immutable, which means they can’t capture mutable variables. This allows operators to move function execution to a Task, which is also why it expects owned 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.

Also note that it would be more efficient to return an impl Iterator from the lift function, but this doesn’t work due to the RPITIT (return-position impl trait in trait) limitations, as they’re not yet stabilized. Once those hit the stable channel, we should consider switching to this approach. We also considered making the lift function generic over the iterator type, but it would make the trait more complex and less ergonomic.

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

Lift data:

use zrx_stream::function::LiftFn;
use zrx_stream::value::Chunk;

// Define and execute function
let f = |data: &Vec<i32>| {
    data.iter()
        .map(|&n| (format!("id/{n}"), n))
        .collect::<Chunk<_, _>>()
};
f.execute(&"id".to_string(), &vec![1, 2])?;

Lift data with splat argument:

use zrx_stream::function::{LiftFn, Splat};
use zrx_stream::value::Chunk;

// Define and execute function
let f = |a: &i32, b: &i32| {
    [a, b]
        .into_iter()
        .map(|&n| (format!("id/{n}"), n))
        .collect::<Chunk<_, _>>()
};
f.execute(&"id".to_string(), &Splat::from((1, 2)))?;

Required Methods§

Source

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

Executes the lift function.

§Errors

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

Implementors§

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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