Skip to main content

coil_ops/
identifiers.rs

1use crate::error::OpsModelError;
2use crate::validation::validate_token;
3use std::fmt;
4
5macro_rules! token_type {
6    ($name:ident, $field:literal) => {
7        #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
8        pub struct $name(String);
9
10        impl $name {
11            pub fn new(value: impl Into<String>) -> Result<Self, OpsModelError> {
12                Ok(Self(validate_token($field, value.into())?))
13            }
14
15            pub fn as_str(&self) -> &str {
16                &self.0
17            }
18        }
19
20        impl fmt::Display for $name {
21            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22                f.write_str(&self.0)
23            }
24        }
25    };
26}
27
28token_type!(SearchIndexId, "search_index_id");
29token_type!(SearchFieldId, "search_field_id");
30token_type!(ReportId, "report_id");
31token_type!(ReportExportId, "report_export_id");
32token_type!(BulkOperationId, "bulk_operation_id");
33token_type!(BulkExecutionId, "bulk_execution_id");
34token_type!(RecoveryWorkflowId, "recovery_workflow_id");
35token_type!(RecoveryExecutionId, "recovery_execution_id");