use super::{
account::{AccountRead, AccountWrite},
blob::{BlobRead, BlobWrite},
map::{MapRead, MapWrite},
sequence::{SequenceRead, SequenceWrite},
AuthorisationKind, CmdError, QueryResponse,
};
use crate::{Error, XorName};
use serde::{Deserialize, Serialize};
use std::fmt;
#[allow(clippy::large_enum_variant)]
#[derive(Hash, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub enum DataCmd {
Blob(BlobWrite),
Map(MapWrite),
Sequence(SequenceWrite),
Account(AccountWrite), }
impl DataCmd {
pub fn error(&self, error: Error) -> CmdError {
use DataCmd::*;
match self {
Blob(c) => c.error(error),
Map(c) => c.error(error),
Sequence(c) => c.error(error),
Account(c) => c.error(error),
}
}
pub fn authorisation_kind(&self) -> AuthorisationKind {
use DataCmd::*;
match self {
Blob(c) => c.authorisation_kind(),
Map(c) => c.authorisation_kind(),
Sequence(c) => c.authorisation_kind(),
Account(c) => c.authorisation_kind(),
}
}
pub fn dst_address(&self) -> XorName {
use DataCmd::*;
match self {
Blob(c) => c.dst_address(),
Map(c) => c.dst_address(),
Sequence(c) => c.dst_address(),
Account(c) => c.dst_address(),
}
}
}
impl fmt::Debug for DataCmd {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use DataCmd::*;
match self {
Blob(c) => write!(formatter, "{:?}", c),
Map(c) => write!(formatter, "{:?}", c),
Sequence(c) => write!(formatter, "{:?}", c),
Account(c) => write!(formatter, "{:?}", c),
}
}
}
#[allow(clippy::large_enum_variant)]
#[derive(Hash, Eq, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
pub enum DataQuery {
Blob(BlobRead),
Map(MapRead),
Sequence(SequenceRead),
Account(AccountRead), }
impl DataQuery {
pub fn error(&self, error: Error) -> QueryResponse {
use DataQuery::*;
match self {
Blob(q) => q.error(error),
Map(q) => q.error(error),
Sequence(q) => q.error(error),
Account(q) => q.error(error),
}
}
pub fn authorisation_kind(&self) -> AuthorisationKind {
use DataQuery::*;
match self {
Blob(q) => q.authorisation_kind(),
Map(q) => q.authorisation_kind(),
Sequence(q) => q.authorisation_kind(),
Account(q) => q.authorisation_kind(),
}
}
pub fn dst_address(&self) -> XorName {
use DataQuery::*;
match self {
Blob(q) => q.dst_address(),
Map(q) => q.dst_address(),
Sequence(q) => q.dst_address(),
Account(q) => q.dst_address(),
}
}
}
impl fmt::Debug for DataQuery {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use DataQuery::*;
match self {
Blob(q) => write!(formatter, "{:?}", q),
Map(q) => write!(formatter, "{:?}", q),
Sequence(q) => write!(formatter, "{:?}", q),
Account(q) => write!(formatter, "{:?}", q),
}
}
}