batch_mode_batch_scribe/
custom_request_id.rs1crate::ix!();
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub struct CustomRequestId(String);
6
7impl CustomRequestId {
8 pub fn new(id: impl Into<String>) -> Self {
9 Self(id.into())
10 }
11
12 pub fn as_str(&self) -> &str {
13 &self.0
14 }
15}
16
17impl std::fmt::Display for CustomRequestId {
18 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19 self.0.fmt(f)
20 }
21}
22
23#[cfg(test)]
24mod custom_request_id_tests {
25 use super::*;
26
27 #[test]
28 fn test_custom_request_id_creation() {
29 let id = CustomRequestId::new("custom_123");
30 pretty_assert_eq!(id.as_str(), "custom_123");
31 }
32
33 #[test]
34 fn test_custom_request_id_serialization() {
35 let id = CustomRequestId::new("custom_456");
36 let serialized = serde_json::to_string(&id).unwrap();
37 pretty_assert_eq!(serialized, "\"custom_456\"");
38 }
39
40 #[test]
41 fn test_custom_request_id_deserialization() {
42 let json_data = "\"custom_789\"";
43 let id: CustomRequestId = serde_json::from_str(json_data).unwrap();
44 pretty_assert_eq!(id.as_str(), "custom_789");
45 }
46}