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