actionqueue_core/ids/
actor_id.rs1use std::fmt::{Display, Formatter};
4use std::str::FromStr;
5
6use uuid::Uuid;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct ActorId(Uuid);
12
13impl ActorId {
14 pub fn new() -> Self {
16 ActorId(Uuid::new_v4())
17 }
18
19 pub fn from_uuid(uuid: Uuid) -> Self {
21 ActorId(uuid)
22 }
23
24 pub fn as_uuid(&self) -> &Uuid {
26 &self.0
27 }
28}
29
30impl Default for ActorId {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36impl FromStr for ActorId {
37 type Err = uuid::Error;
38
39 fn from_str(s: &str) -> Result<Self, Self::Err> {
40 Uuid::from_str(s).map(ActorId)
41 }
42}
43
44impl Display for ActorId {
45 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
46 write!(f, "{}", self.0)
47 }
48}