1use crate::types::{Id, PublicKey};
2
3#[derive(Debug, PartialEq, Clone)]
4#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
5pub enum PageInfo {
6 Primary(Primary),
7 Secondary(Secondary),
8 Data(()),
9}
10
11impl PageInfo {
12 pub fn primary(pub_key: PublicKey) -> Self {
13 PageInfo::Primary(Primary { pub_key })
14 }
15
16 pub fn secondary(peer_id: Id) -> Self {
17 PageInfo::Secondary(Secondary { peer_id })
18 }
19
20 pub fn is_primary(&self) -> bool {
21 match self {
22 PageInfo::Primary(_) => true,
23 _ => false,
24 }
25 }
26
27 pub fn is_secondary(&self) -> bool {
28 match self {
29 PageInfo::Secondary(_) => true,
30 _ => false,
31 }
32 }
33
34 pub fn pub_key(&self) -> Option<PublicKey> {
35 match self {
36 PageInfo::Primary(p) => Some(p.pub_key.clone()),
37 _ => None,
38 }
39 }
40
41 pub fn peer_id(&self) -> Option<Id> {
42 match self {
43 PageInfo::Secondary(s) => Some(s.peer_id.clone()),
44 _ => None,
45 }
46 }
47}
48
49#[derive(Debug, PartialEq, Clone)]
50#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
51pub struct Primary {
52 pub pub_key: PublicKey,
53}
54
55#[derive(Debug, PartialEq, Clone)]
56#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
57pub struct Secondary {
58 pub peer_id: Id,
59}