Skip to main content

agent_storage/family/
family_id.rs

1//! Stable identifier assigned to a family.
2
3use serde::{Deserialize, Serialize};
4use std::str::FromStr;
5use uuid::Uuid;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(transparent)]
9pub struct FamilyId(Uuid);
10
11impl FamilyId {
12    pub fn new() -> Self {
13        Self(Uuid::new_v4())
14    }
15}
16impl Default for FamilyId {
17    fn default() -> Self {
18        Self::new()
19    }
20}
21impl std::fmt::Display for FamilyId {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        self.0.fmt(f)
24    }
25}
26impl FromStr for FamilyId {
27    type Err = uuid::Error;
28
29    fn from_str(value: &str) -> Result<Self, Self::Err> {
30        Uuid::parse_str(value).map(Self)
31    }
32}