1use std::{
2 fmt,
3 hash::{Hash, Hasher},
4 sync::Arc,
5};
6
7pub type ActorId = usize;
8pub struct ActorPath(Arc<String>);
9
10impl ActorPath {
11 #[must_use]
12 pub fn new(path: &str) -> Self {
13 Self(Arc::new(path.to_string()))
14 }
15}
16
17impl PartialEq for ActorPath {
18 fn eq(&self, other: &Self) -> bool {
19 self.0 == other.0
20 }
21}
22
23impl PartialEq<str> for ActorPath {
24 fn eq(&self, other: &str) -> bool {
25 *self.0 == other
26 }
27}
28
29impl Eq for ActorPath {}
30
31impl Hash for ActorPath {
32 fn hash<H: Hasher>(&self, state: &mut H) {
33 self.0.hash(state);
34 }
35}
36
37impl fmt::Display for ActorPath {
38 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39 write!(f, "{}", self.0)
40 }
41}
42
43impl fmt::Debug for ActorPath {
44 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45 write!(f, "{:?}", self.0)
46 }
47}
48
49impl Clone for ActorPath {
50 fn clone(&self) -> Self {
51 Self(self.0.clone())
52 }
53}
54
55#[derive(Clone)]
61pub struct ActorUri {
62 pub uid: ActorId,
63 pub name: Arc<String>,
64 pub path: ActorPath,
65 pub host: Arc<String>,
66}
67
68impl PartialEq for ActorUri {
69 fn eq(&self, other: &Self) -> bool {
70 self.path == other.path
71 }
72}
73
74impl Eq for ActorUri {}
75
76impl Hash for ActorUri {
77 fn hash<H: Hasher>(&self, state: &mut H) {
78 self.path.hash(state);
79 }
80}
81
82impl fmt::Display for ActorUri {
83 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
84 write!(f, "{}", self.path)
85 }
86}
87
88impl fmt::Debug for ActorUri {
89 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
90 write!(f, "{}://{}#{}", self.host, self.path, self.uid)
91 }
92}