datadog_agent_remote_config/
product.rs1use std::fmt;
2use std::ops::Deref;
3
4#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
12pub struct ConfigId(pub(crate) String);
13
14impl ConfigId {
15 pub fn new(id: impl Into<String>) -> Self {
20 Self(id.into())
21 }
22}
23
24impl Deref for ConfigId {
25 type Target = str;
26
27 fn deref(&self) -> &Self::Target {
28 &self.0
29 }
30}
31
32impl fmt::Display for ConfigId {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 self.0.fmt(f)
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use crate::product::ConfigId;
41
42 #[test]
43 fn config_id_derefs_to_str_for_matching() {
44 let config_id = ConfigId::new("semantic.v1");
45
46 assert!(matches!(&*config_id, "semantic.v1"));
47 assert_eq!("semantic.v1", config_id.to_string());
48 }
49
50 #[test]
51 fn config_ids_order_ascending_by_id() {
52 let mut ids = [
53 ConfigId("registry.v3".to_string()),
54 ConfigId("registry.v1".to_string()),
55 ConfigId("registry.v2".to_string()),
56 ];
57 ids.sort();
58
59 let sorted: Vec<&str> = ids.iter().map(|id| &**id).collect();
60 assert_eq!(vec!["registry.v1", "registry.v2", "registry.v3"], sorted);
61 }
62}