1#[non_exhaustive]
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
36pub enum TransportKind {
37 Kafka,
38 Grpc,
39 Memory,
40 File,
41 Pipe,
42 Http,
43 Redis,
44 Routed,
45 Output,
49}
50
51impl TransportKind {
52 #[must_use]
54 pub const fn as_label(self) -> &'static str {
55 match self {
56 Self::Kafka => "kafka",
57 Self::Grpc => "grpc",
58 Self::Memory => "memory",
59 Self::File => "file",
60 Self::Pipe => "pipe",
61 Self::Http => "http",
62 Self::Redis => "redis",
63 Self::Routed => "routed",
64 Self::Output => "output",
65 }
66 }
67}
68
69impl std::fmt::Display for TransportKind {
70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 f.write_str(self.as_label())
72 }
73}
74
75#[non_exhaustive]
78#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
79pub enum FlushTrigger {
80 Size,
82 Records,
84 Age,
86 Eviction,
88 Shutdown,
90 Manual,
92}
93
94impl FlushTrigger {
95 #[must_use]
96 pub const fn as_label(self) -> &'static str {
97 match self {
98 Self::Size => "size",
99 Self::Records => "records",
100 Self::Age => "age",
101 Self::Eviction => "eviction",
102 Self::Shutdown => "shutdown",
103 Self::Manual => "manual",
104 }
105 }
106}
107
108impl std::fmt::Display for FlushTrigger {
109 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110 f.write_str(self.as_label())
111 }
112}
113
114#[non_exhaustive]
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
121pub enum AuthFailureReason {
122 Expired,
124 InvalidSignature,
126 InvalidClient,
128 InvalidGrant,
130 InvalidScope,
132 MalformedToken,
134 RevokedToken,
136 RateLimited,
138 Unauthorized,
140 AccessDenied,
142}
143
144impl AuthFailureReason {
145 #[must_use]
146 pub const fn as_label(self) -> &'static str {
147 match self {
148 Self::Expired => "expired",
149 Self::InvalidSignature => "invalid_signature",
150 Self::InvalidClient => "invalid_client",
151 Self::InvalidGrant => "invalid_grant",
152 Self::InvalidScope => "invalid_scope",
153 Self::MalformedToken => "malformed_token",
154 Self::RevokedToken => "revoked_token",
155 Self::RateLimited => "rate_limited",
156 Self::Unauthorized => "unauthorized",
157 Self::AccessDenied => "access_denied",
158 }
159 }
160}
161
162impl std::fmt::Display for AuthFailureReason {
163 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
164 f.write_str(self.as_label())
165 }
166}
167
168#[non_exhaustive]
172#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
173pub enum ValidationFailureReason {
174 SchemaInvalid,
176 FieldMissing,
178 TypeMismatch,
180 OutOfRange,
182 PatternMismatch,
184 FormatInvalid,
186 EnumViolation,
188 AdditionalProperties,
190 NullValue,
192 EncodingError,
194}
195
196impl ValidationFailureReason {
197 #[must_use]
198 pub const fn as_label(self) -> &'static str {
199 match self {
200 Self::SchemaInvalid => "schema_invalid",
201 Self::FieldMissing => "field_missing",
202 Self::TypeMismatch => "type_mismatch",
203 Self::OutOfRange => "out_of_range",
204 Self::PatternMismatch => "pattern_mismatch",
205 Self::FormatInvalid => "format_invalid",
206 Self::EnumViolation => "enum_violation",
207 Self::AdditionalProperties => "additional_properties",
208 Self::NullValue => "null_value",
209 Self::EncodingError => "encoding_error",
210 }
211 }
212}
213
214impl std::fmt::Display for ValidationFailureReason {
215 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
216 f.write_str(self.as_label())
217 }
218}
219
220#[cfg(test)]
221mod tests {
222 use super::*;
223
224 #[test]
228 fn label_values_are_snake_case_ascii() {
229 let all: &[&str] = &[
230 TransportKind::Kafka.as_label(),
231 TransportKind::Grpc.as_label(),
232 TransportKind::Memory.as_label(),
233 TransportKind::File.as_label(),
234 TransportKind::Pipe.as_label(),
235 TransportKind::Http.as_label(),
236 TransportKind::Redis.as_label(),
237 TransportKind::Routed.as_label(),
238 TransportKind::Output.as_label(),
239 FlushTrigger::Size.as_label(),
240 FlushTrigger::Records.as_label(),
241 FlushTrigger::Age.as_label(),
242 FlushTrigger::Eviction.as_label(),
243 FlushTrigger::Shutdown.as_label(),
244 FlushTrigger::Manual.as_label(),
245 AuthFailureReason::Expired.as_label(),
246 AuthFailureReason::InvalidSignature.as_label(),
247 AuthFailureReason::InvalidClient.as_label(),
248 AuthFailureReason::InvalidGrant.as_label(),
249 AuthFailureReason::InvalidScope.as_label(),
250 AuthFailureReason::MalformedToken.as_label(),
251 AuthFailureReason::RevokedToken.as_label(),
252 AuthFailureReason::RateLimited.as_label(),
253 AuthFailureReason::Unauthorized.as_label(),
254 AuthFailureReason::AccessDenied.as_label(),
255 ValidationFailureReason::SchemaInvalid.as_label(),
256 ValidationFailureReason::FieldMissing.as_label(),
257 ValidationFailureReason::TypeMismatch.as_label(),
258 ValidationFailureReason::OutOfRange.as_label(),
259 ValidationFailureReason::PatternMismatch.as_label(),
260 ValidationFailureReason::FormatInvalid.as_label(),
261 ValidationFailureReason::EnumViolation.as_label(),
262 ValidationFailureReason::AdditionalProperties.as_label(),
263 ValidationFailureReason::NullValue.as_label(),
264 ValidationFailureReason::EncodingError.as_label(),
265 ];
266 for s in all {
267 assert!(
268 s.bytes()
269 .all(|b| b.is_ascii_lowercase() || b == b'_' || b.is_ascii_digit()),
270 "non-snake-case label: {s:?}"
271 );
272 assert!(!s.is_empty(), "empty label");
273 }
274 }
275}