safe_nd/messaging/
data.rs1use super::{
11 account::{AccountRead, AccountWrite},
12 blob::{BlobRead, BlobWrite},
13 map::{MapRead, MapWrite},
14 sequence::{SequenceRead, SequenceWrite},
15 AuthorisationKind, CmdError, QueryResponse,
16};
17use crate::{Error, XorName};
18use serde::{Deserialize, Serialize};
19use std::fmt;
20
21#[allow(clippy::large_enum_variant)]
23#[derive(Hash, Eq, PartialEq, Clone, Serialize, Deserialize)]
24pub enum DataCmd {
25 Blob(BlobWrite),
27 Map(MapWrite),
29 Sequence(SequenceWrite),
31 Account(AccountWrite), }
35
36impl DataCmd {
37 pub fn error(&self, error: Error) -> CmdError {
40 use DataCmd::*;
41 match self {
42 Blob(c) => c.error(error),
43 Map(c) => c.error(error),
44 Sequence(c) => c.error(error),
45 Account(c) => c.error(error),
46 }
47 }
48 pub fn authorisation_kind(&self) -> AuthorisationKind {
50 use DataCmd::*;
51 match self {
52 Blob(c) => c.authorisation_kind(),
53 Map(c) => c.authorisation_kind(),
54 Sequence(c) => c.authorisation_kind(),
55 Account(c) => c.authorisation_kind(),
56 }
57 }
58
59 pub fn dst_address(&self) -> XorName {
61 use DataCmd::*;
62 match self {
63 Blob(c) => c.dst_address(),
64 Map(c) => c.dst_address(),
65 Sequence(c) => c.dst_address(),
66 Account(c) => c.dst_address(),
67 }
68 }
69}
70
71impl fmt::Debug for DataCmd {
72 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
73 use DataCmd::*;
74 match self {
75 Blob(c) => write!(formatter, "{:?}", c),
76 Map(c) => write!(formatter, "{:?}", c),
77 Sequence(c) => write!(formatter, "{:?}", c),
78 Account(c) => write!(formatter, "{:?}", c),
79 }
80 }
81}
82
83#[allow(clippy::large_enum_variant)]
85#[derive(Hash, Eq, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
86pub enum DataQuery {
87 Blob(BlobRead),
89 Map(MapRead),
91 Sequence(SequenceRead),
93 Account(AccountRead), }
97
98impl DataQuery {
99 pub fn error(&self, error: Error) -> QueryResponse {
102 use DataQuery::*;
103 match self {
104 Blob(q) => q.error(error),
105 Map(q) => q.error(error),
106 Sequence(q) => q.error(error),
107 Account(q) => q.error(error),
108 }
109 }
110
111 pub fn authorisation_kind(&self) -> AuthorisationKind {
113 use DataQuery::*;
114 match self {
115 Blob(q) => q.authorisation_kind(),
116 Map(q) => q.authorisation_kind(),
117 Sequence(q) => q.authorisation_kind(),
118 Account(q) => q.authorisation_kind(),
119 }
120 }
121
122 pub fn dst_address(&self) -> XorName {
124 use DataQuery::*;
125 match self {
126 Blob(q) => q.dst_address(),
127 Map(q) => q.dst_address(),
128 Sequence(q) => q.dst_address(),
129 Account(q) => q.dst_address(),
130 }
131 }
132}
133
134impl fmt::Debug for DataQuery {
135 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
136 use DataQuery::*;
137 match self {
138 Blob(q) => write!(formatter, "{:?}", q),
139 Map(q) => write!(formatter, "{:?}", q),
140 Sequence(q) => write!(formatter, "{:?}", q),
141 Account(q) => write!(formatter, "{:?}", q),
142 }
143 }
144}