batch_mode_batch_scribe/
batch_request_id.rs

1// ---------------- [ File: batch-mode-batch-scribe/src/batch_request_id.rs ]
2crate::ix!();
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub struct BatchRequestId(String);
6
7impl BatchRequestId {
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 BatchRequestId {
18    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19        self.0.fmt(f)
20    }
21}
22
23#[cfg(test)]
24mod batch_request_id_tests {
25    use super::*;
26
27    #[test]
28    fn test_batch_request_id_creation() {
29        let id = BatchRequestId::new("batch_123");
30        pretty_assert_eq!(id.as_str(), "batch_123");
31    }
32
33    #[test]
34    fn test_batch_request_id_serialization() {
35        let id = BatchRequestId::new("batch_456");
36        let serialized = serde_json::to_string(&id).unwrap();
37        pretty_assert_eq!(serialized, "\"batch_456\"");
38    }
39
40    #[test]
41    fn test_batch_request_id_deserialization() {
42        let json_data = "\"batch_789\"";
43        let id: BatchRequestId = serde_json::from_str(json_data).unwrap();
44        pretty_assert_eq!(id.as_str(), "batch_789");
45    }
46}