pub trait DefaultFn<I, T>: Send + 'static {
// Required method
fn execute(&self, id: &I) -> Result<Option<T>>;
}Expand description
Default function.
This trait defines a function allowing to create a value of type T from an
optional identifier. It is useful in scenarios where you want to ensure that
each item in a stream has associated data, such as providing default values
when none are present.
This trait is also implemented for the [WithId] adapter. 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
use zrx_stream::function::DefaultFn;
// Define and execute function
let f = || Some(42);
f.execute(&"id")?;