saluki_core/components/encoders/builder.rs
1#![allow(dead_code)]
2
3use async_trait::async_trait;
4use memory_accounting::MemoryBounds;
5use saluki_error::GenericError;
6
7use super::{Encoder, IncrementalEncoder};
8use crate::{
9 components::ComponentContext,
10 data_model::{event::EventType, payload::PayloadType},
11};
12
13/// A encoder builder.
14///
15/// Encoder builders are responsible for creating instances of [`Encoder`]s, as well as describing high-level
16/// aspects of the built encoder, such as the data types allowed for input events and the outputs exposed by the
17/// encoder.
18#[async_trait]
19pub trait EncoderBuilder: MemoryBounds {
20 /// Data types allowed as input payloads to this encoder.
21 fn input_event_type(&self) -> EventType;
22
23 /// Data types emitted as output payloads by this encoder.
24 fn output_payload_type(&self) -> PayloadType;
25
26 /// Builds an instance of the encoder.
27 ///
28 /// # Errors
29 ///
30 /// If the encoder cannot be built for any reason, an error is returned.
31 async fn build(&self, context: ComponentContext) -> Result<Box<dyn Encoder + Send>, GenericError>;
32}
33
34/// An incremental encoder builder.
35///
36/// Incremental encoder builders are responsible for creating instances of [`IncrementalEncoder`]s, as well as
37/// describing high-level aspects of the built incremental encoder, such as the data types allowed for input events and
38/// the outputs exposed by the incremental encoder.
39#[async_trait]
40pub trait IncrementalEncoderBuilder: MemoryBounds {
41 /// Type of the incremental encoder to be built.
42 type Output: IncrementalEncoder;
43
44 /// Data types allowed as input payloads to this incremental encoder.
45 fn input_event_type(&self) -> EventType;
46
47 /// Data types emitted as output payloads by this incremental encoder.
48 fn output_payload_type(&self) -> PayloadType;
49
50 /// Builds an instance of the incremental encoder.
51 ///
52 /// # Errors
53 ///
54 /// If the incremental encoder cannot be built for any reason, an error is returned.
55 async fn build(&self, context: ComponentContext) -> Result<Self::Output, GenericError>;
56}