stasis/domain/value_objects/
agent_id.rs1use crate::domain::errors::{Result, StasisError};
2
3#[derive(Clone, Debug, Hash, Eq, PartialEq)]
4pub struct AgentId(String);
5
6impl AgentId {
7 pub fn new(value: String) -> Result<Self> {
8 let trimmed = value.trim();
9
10 if trimmed.is_empty() {
11 return Err(StasisError::InvalidAgentId(value));
12 }
13
14 if !trimmed
15 .chars()
16 .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-' || c == '_')
17 {
18 return Err(StasisError::InvalidAgentId(value));
19 }
20
21 Ok(Self(trimmed.to_string()))
22 }
23
24 pub fn as_str(&self) -> &str {
25 &self.0
26 }
27}
28
29impl From<AgentId> for String {
30 fn from(value: AgentId) -> Self {
31 value.0
32 }
33}