46 lines
1.0 KiB
Rust
46 lines
1.0 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
macro_rules! define_id {
|
|
($name:ident) => {
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
|
pub struct $name(String);
|
|
|
|
impl $name {
|
|
pub fn new(value: impl Into<String>) -> Self {
|
|
Self(value.into())
|
|
}
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl From<String> for $name {
|
|
fn from(value: String) -> Self {
|
|
Self(value)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for $name {
|
|
fn from(value: &str) -> Self {
|
|
Self(value.to_owned())
|
|
}
|
|
}
|
|
|
|
impl AsRef<str> for $name {
|
|
fn as_ref(&self) -> &str {
|
|
self.as_str()
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
define_id!(OperationId);
|
|
define_id!(DescriptorId);
|
|
define_id!(ToolId);
|
|
define_id!(SampleId);
|
|
define_id!(AuthProfileId);
|
|
define_id!(WorkspaceId);
|
|
define_id!(UserId);
|
|
define_id!(AgentId);
|