shepherd_rs/transform/request.rs
1//! # Transform Request Trait
2//!
3//! This trait defines the behavior of transformation requests in the
4//! shepherd framework.
5//!
6//! ## Overview
7//! - **TransformRequest**: Represents a request to transform input data into
8//! output data.
9//! - **Identifier**: Provides unique identifiers for tracking requests.
10//!
11//! ## Example
12//! ```rust
13//! struct MyTransformRequest;
14//!
15//! impl TransformRequest for MyTransformRequest {
16//! // Implementation details...
17//! }
18//! ```
19
20use std::fmt::Debug;
21
22/// A trait representing a transformation request in shepherd-rs processing
23/// system. Each transformation request is a request to transform some input
24/// data into an output format. As such, the `Input` and `Output` types are
25/// generic, associated types allowing for flexibility in the types of data
26/// being transformed.
27pub trait TransformRequest: Send + Sync + Debug + Clone {
28 /// A unique identifier for the transformation request.
29 /// This needs to be unique across all transformation requests,
30 /// across different shepherd-rs instances (process failures, etc.).
31 type Identifier: Send + Sync + Eq + Debug;
32
33 /// The type of the input for the transformation.
34 type Input: Send + Clone;
35
36 /// The type of the output expected after the transformation.
37 type Output: Send + Clone;
38
39 /// Returns the unique identifier for the transformation request.
40 fn request_id(&self) -> Self::Identifier;
41
42 /// Returns the input for the transformation request.
43 fn input(&self) -> &Self::Input;
44
45 /// Given the TransformRequest is the latest in the stream,
46 /// what dynamic configs need to be updated, Key is always a
47 /// string, value is always a `Vec<u8>` representing the serialized
48 /// value
49 fn get_dyn_configs(&self) -> Vec<(String, Vec<u8>)>;
50}
51
52#[cfg(test)]
53#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
54pub struct NilTR;
55
56#[cfg(test)]
57impl TransformRequest for NilTR {
58 type Identifier = ();
59 type Input = ();
60 type Output = ();
61
62 fn request_id(&self) -> Self::Identifier { () }
63
64 fn input(&self) -> &Self::Input { &() }
65
66 fn get_dyn_configs(&self) -> Vec<(String, Vec<u8>)> { vec![] }
67}