Skip to main content

dactor/
node.rs

1use std::fmt;
2
3/// Unique identifier for a node in the cluster.
4#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct NodeId(pub String);
7
8impl fmt::Display for NodeId {
9    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10        write!(f, "Node({})", self.0)
11    }
12}
13
14impl From<&str> for NodeId {
15    fn from(s: &str) -> Self {
16        NodeId(s.to_string())
17    }
18}
19
20impl From<String> for NodeId {
21    fn from(s: String) -> Self {
22        NodeId(s)
23    }
24}
25
26/// Globally unique identifier for an actor across all nodes in a cluster.
27#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29pub struct ActorId {
30    /// The node that spawned this actor.
31    pub node: NodeId,
32    /// Node-local monotonically increasing sequence number.
33    pub local: u64,
34}
35
36impl fmt::Display for ActorId {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        write!(f, "Actor({}/{})", self.node.0, self.local)
39    }
40}