Skip to main content

rewrit_model/
ids.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5macro_rules! id_type {
6    ($name:ident) => {
7        #[derive(
8            Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
9        )]
10        #[serde(transparent)]
11        pub struct $name(pub String);
12
13        impl $name {
14            #[must_use]
15            pub fn new(value: impl Into<String>) -> Self {
16                Self(value.into())
17            }
18
19            #[must_use]
20            pub fn as_str(&self) -> &str {
21                &self.0
22            }
23        }
24
25        impl From<&str> for $name {
26            fn from(value: &str) -> Self {
27                Self::new(value)
28            }
29        }
30
31        impl From<String> for $name {
32            fn from(value: String) -> Self {
33                Self::new(value)
34            }
35        }
36
37        impl AsRef<str> for $name {
38            fn as_ref(&self) -> &str {
39                self.as_str()
40            }
41        }
42
43        impl fmt::Display for $name {
44            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45                f.write_str(self.as_str())
46            }
47        }
48    };
49}
50
51id_type!(CaseId);
52id_type!(SuiteId);
53id_type!(RuntimeId);
54id_type!(AdapterId);