Skip to main content

coil_admin/
ids.rs

1use std::fmt;
2
3use crate::error::AdminModelError;
4use crate::validation::validate_token;
5
6macro_rules! token_type {
7    ($name:ident, $field:literal) => {
8        #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9        pub struct $name(String);
10
11        impl $name {
12            pub fn new(value: impl Into<String>) -> Result<Self, AdminModelError> {
13                Ok(Self(validate_token($field, value.into())?))
14            }
15        }
16
17        impl fmt::Display for $name {
18            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19                f.write_str(&self.0)
20            }
21        }
22    };
23}
24
25token_type!(AdminResourceId, "admin_resource_id");
26token_type!(AdminWidgetId, "admin_widget_id");
27token_type!(WorkflowId, "workflow_id");
28token_type!(AuditEntryId, "audit_entry_id");
29token_type!(ResourceKind, "resource_kind");