gpt_batch_scribe/
custom_request_id.rs

1crate::ix!();
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
4pub struct CustomRequestId(String);
5
6impl CustomRequestId {
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 CustomRequestId {
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_custom_request_id_creation() {
28        let id = CustomRequestId::new("custom_123");
29        assert_eq!(id.as_str(), "custom_123");
30    }
31
32    #[test]
33    fn test_custom_request_id_serialization() {
34        let id = CustomRequestId::new("custom_456");
35        let serialized = serde_json::to_string(&id).unwrap();
36        assert_eq!(serialized, "\"custom_456\"");
37    }
38
39    #[test]
40    fn test_custom_request_id_deserialization() {
41        let json_data = "\"custom_789\"";
42        let id: CustomRequestId = serde_json::from_str(json_data).unwrap();
43        assert_eq!(id.as_str(), "custom_789");
44    }
45}
46