batch_mode_batch_scribe/
custom_request_id.rs

1// ---------------- [ File: batch-mode-batch-scribe/src/custom_request_id.rs ]
2crate::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// batch-mode-batch-scribe/src/custom_request_id.rs
24impl AsRef<str> for CustomRequestId {
25    fn as_ref(&self) -> &str { self.as_str() }
26}
27
28#[cfg(test)]
29mod custom_request_id_tests {
30    use super::*;
31
32    #[test]
33    fn test_custom_request_id_creation() {
34        let id = CustomRequestId::new("custom_123");
35        pretty_assert_eq!(id.as_str(), "custom_123");
36    }
37
38    #[test]
39    fn test_custom_request_id_serialization() {
40        let id = CustomRequestId::new("custom_456");
41        let serialized = serde_json::to_string(&id).unwrap();
42        pretty_assert_eq!(serialized, "\"custom_456\"");
43    }
44
45    #[test]
46    fn test_custom_request_id_deserialization() {
47        let json_data = "\"custom_789\"";
48        let id: CustomRequestId = serde_json::from_str(json_data).unwrap();
49        pretty_assert_eq!(id.as_str(), "custom_789");
50    }
51}