1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use holo_hash::AgentPubKey;
use holo_hash::DnaHash;
use holochain_serialized_bytes::prelude::*;
use std::fmt;
#[derive(
Clone,
Debug,
Hash,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
SerializedBytes,
Ord,
PartialOrd,
)]
pub struct CellId(DnaHash, AgentPubKey);
impl fmt::Display for CellId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Cell({}, {})", self.dna_hash(), self.agent_pubkey())
}
}
impl CellId {
pub fn new(dna_hash: DnaHash, agent_pubkey: AgentPubKey) -> Self {
CellId(dna_hash, agent_pubkey)
}
pub fn dna_hash(&self) -> &DnaHash {
&self.0
}
pub fn agent_pubkey(&self) -> &AgentPubKey {
&self.1
}
pub fn into_dna_and_agent(self) -> (DnaHash, AgentPubKey) {
(self.0, self.1)
}
}
impl From<(DnaHash, AgentPubKey)> for CellId {
fn from(pair: (DnaHash, AgentPubKey)) -> Self {
Self(pair.0, pair.1)
}
}