saluki_core/components/transforms/builder.rs
1use async_trait::async_trait;
2use memory_accounting::MemoryBounds;
3use saluki_error::GenericError;
4
5use super::{SynchronousTransform, Transform};
6use crate::{components::ComponentContext, data_model::event::EventType, topology::OutputDefinition};
7
8/// A transform builder.
9///
10/// Transform builders are responsible for creating instances of [`Transform`]s, as well as describing high-level
11/// aspects of the built transform, such as the data types allowed for input events and the outputs exposed by the
12/// transform.
13#[async_trait]
14pub trait TransformBuilder: MemoryBounds {
15 /// Event type allowed as input events to this transform.
16 fn input_event_type(&self) -> EventType;
17
18 /// Event outputs exposed by this transform.
19 fn outputs(&self) -> &[OutputDefinition];
20
21 /// Builds an instance of the transform.
22 ///
23 /// ## Errors
24 ///
25 /// If the transform cannot be built for any reason, an error is returned.
26 async fn build(&self, context: ComponentContext) -> Result<Box<dyn Transform + Send>, GenericError>;
27}
28
29/// A synchronous transform builder.
30///
31/// Synchronous transforms are a special case of transforms that are executed synchronously, meaning that they do not
32/// run as their own task. This is used for certain transforms, typically those where it is more efficient to run
33/// multiple transformation steps in a single task.
34#[async_trait]
35pub trait SynchronousTransformBuilder: MemoryBounds {
36 /// Builds an instance of the synchronous transform.
37 ///
38 /// The provided context is relative to the parent component that is building this synchronous transform.
39 ///
40 /// ## Errors
41 ///
42 /// If the synchronous transform cannot be built for any reason, an error is returned.
43 async fn build(&self, context: ComponentContext) -> Result<Box<dyn SynchronousTransform + Send>, GenericError>;
44}