saluki_core/components/
mod.rs1use std::fmt;
4
5use crate::topology::ComponentId;
6
7pub mod destinations;
8pub mod encoders;
9pub mod forwarders;
10pub mod sources;
11pub mod transforms;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub enum ComponentType {
16 Source,
18
19 Transform,
21
22 Destination,
24
25 Forwarder,
27
28 Encoder,
30}
31
32impl ComponentType {
33 pub fn as_str(&self) -> &'static str {
35 match self {
36 Self::Source => "source",
37 Self::Transform => "transform",
38 Self::Destination => "destination",
39 Self::Forwarder => "forwarder",
40 Self::Encoder => "encoder",
41 }
42 }
43}
44
45#[derive(Clone)]
53pub struct ComponentContext {
54 component_id: ComponentId,
55 component_type: ComponentType,
56}
57
58impl ComponentContext {
59 pub fn source(component_id: ComponentId) -> Self {
61 Self {
62 component_id,
63 component_type: ComponentType::Source,
64 }
65 }
66
67 pub fn transform(component_id: ComponentId) -> Self {
69 Self {
70 component_id,
71 component_type: ComponentType::Transform,
72 }
73 }
74
75 pub fn destination(component_id: ComponentId) -> Self {
77 Self {
78 component_id,
79 component_type: ComponentType::Destination,
80 }
81 }
82
83 pub fn forwarder(component_id: ComponentId) -> Self {
85 Self {
86 component_id,
87 component_type: ComponentType::Forwarder,
88 }
89 }
90
91 pub fn encoder(component_id: ComponentId) -> Self {
93 Self {
94 component_id,
95 component_type: ComponentType::Encoder,
96 }
97 }
98
99 #[cfg(test)]
101 pub fn test_source<S: AsRef<str>>(component_id: S) -> Self {
102 Self {
103 component_id: ComponentId::try_from(component_id.as_ref()).expect("invalid component ID"),
104 component_type: ComponentType::Source,
105 }
106 }
107
108 #[cfg(test)]
110 pub fn test_transform<S: AsRef<str>>(component_id: S) -> Self {
111 Self {
112 component_id: ComponentId::try_from(component_id.as_ref()).expect("invalid component ID"),
113 component_type: ComponentType::Transform,
114 }
115 }
116
117 #[cfg(test)]
119 pub fn test_destination<S: AsRef<str>>(component_id: S) -> Self {
120 Self {
121 component_id: ComponentId::try_from(component_id.as_ref()).expect("invalid component ID"),
122 component_type: ComponentType::Destination,
123 }
124 }
125
126 #[cfg(test)]
128 pub fn test_forwarder<S: AsRef<str>>(component_id: S) -> Self {
129 Self {
130 component_id: ComponentId::try_from(component_id.as_ref()).expect("invalid component ID"),
131 component_type: ComponentType::Forwarder,
132 }
133 }
134
135 #[cfg(test)]
137 pub fn test_encoder<S: AsRef<str>>(component_id: S) -> Self {
138 Self {
139 component_id: ComponentId::try_from(component_id.as_ref()).expect("invalid component ID"),
140 component_type: ComponentType::Encoder,
141 }
142 }
143
144 pub fn component_id(&self) -> &ComponentId {
146 &self.component_id
147 }
148
149 pub fn component_type(&self) -> ComponentType {
151 self.component_type
152 }
153}
154
155impl fmt::Display for ComponentContext {
156 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
157 write!(f, "{}[{}]", self.component_type.as_str(), self.component_id)
158 }
159}