pub trait Operator<I, T> {
type Item<'a>: TryFromInputItem<'a, I>;
// Required method
fn descriptor(&self) -> Descriptor;
// Provided methods
fn handle(&mut self, item: Self::Item<'_>) -> impl IntoOutputs<I> { ... }
fn notify(&mut self, signal: Signal<'_, I>) -> impl IntoOutputs<I> { ... }
}Expand description
Operator.
Required Associated Types§
Sourcetype Item<'a>: TryFromInputItem<'a, I>
type Item<'a>: TryFromInputItem<'a, I>
Item type handled by operator.
Required Methods§
Sourcefn descriptor(&self) -> Descriptor
fn descriptor(&self) -> Descriptor
Returns the descriptor of the operator.
Provided Methods§
Sourcefn handle(&mut self, item: Self::Item<'_>) -> impl IntoOutputs<I>
fn handle(&mut self, item: Self::Item<'_>) -> impl IntoOutputs<I>
Handles the given item.
This method is called by the scheduler to handle an item from a stream,
and receives a mutable reference, since operators are allowed to change
their internal state at any given time. Anything which can be converted
into Outputs can be returned, e.g., items, signals and tasks.
We deliberately decided to use an RPIT (return-position impl trait), as it’s the most convenient to work with, instead of requiring yet another associated type to be defined.
Sourcefn notify(&mut self, signal: Signal<'_, I>) -> impl IntoOutputs<I>
fn notify(&mut self, signal: Signal<'_, I>) -> impl IntoOutputs<I>
Notifies the operator of a signal.
This method allows the operator to react to system messages or custom events, which can be used to change its internal state or to trigger specific actions. The default implementation just swallows the signal, which is suitable for most cases.
As with Operator::handle, this method is allowed to return anything
that can be converted into Outputs, expecting it to emit one or
more output items, further signals, tasks or nothing at all.
Warning: only implement this method if the operator is expected to react to signals. Otherwise, the default implementation is sufficient.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.