Skip to main content

CommonLibrary/Transport/DTO/
Correlation.rs

1#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
2//! Correlation ID types and utilities.
3
4/// Correlation ID type.
5///
6/// Used to uniquely identify requests and match responses to requests.
7pub type CorrelationId = String;
8
9/// Trait for generating correlation IDs.
10///
11/// This allows different ID generation strategies (UUID, sequential, etc.)
12/// for testing or special requirements.
13pub trait CorrelationIdGenerator {
14	/// Generates a new unique correlation ID.
15	fn Generate() -> CorrelationId;
16}
17
18/// UUID-based correlation ID generator.
19pub struct UuidCorrelationIdGenerator;
20
21impl CorrelationIdGenerator for UuidCorrelationIdGenerator {
22	fn Generate() -> CorrelationId { uuid::Uuid::new_v4().to_string() }
23}
24
25#[cfg(test)]
26mod tests {
27	use super::*;
28
29	#[test]
30	fn TestCorrelationIdGeneration() {
31		let Identifier1 = UuidCorrelationIdGenerator::Generate();
32		let Identifier2 = UuidCorrelationIdGenerator::Generate();
33		assert!(!Identifier1.is_empty());
34		assert!(!Identifier2.is_empty());
35		assert_ne!(Identifier1, Identifier2);
36	}
37}