use super::{Error, Guarantee, OperationId, PersistentRow, TableProtocol};
use core::marker::PhantomData;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Receipt(OperationId);
impl Receipt {
#[doc(hidden)]
pub const fn from_operation(operation: OperationId) -> Self {
Self(operation)
}
#[doc(hidden)]
pub const fn operation(self) -> OperationId {
self.0
}
}
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Answer<Value, Refusal> {
Ready(Result<Value, Refusal>),
Pending,
Unavailable(Error),
}
#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MutationAnswer<Outcome, Refusal> {
Pending {
receipt: Receipt,
outcome: Result<Outcome, Refusal>,
established: Guarantee,
},
Confirmed {
receipt: Receipt,
outcome: Result<Outcome, Refusal>,
established: Guarantee,
},
Unknown,
Unavailable(Error),
}
#[derive(Debug, PartialEq, Eq)]
pub struct TableMutation<Command> {
pub receipt: Receipt,
pub command: Command,
pub guarantee: Guarantee,
}
impl<Command> TableMutation<Command> {
pub fn into_request<Query>(self) -> TableRequest<Query, Command> {
TableRequest::Mutate {
receipt: self.receipt,
command: self.command,
guarantee: self.guarantee,
}
}
}
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TableRequest<Query, Mutation> {
Read {
query: Query,
guarantee: Guarantee,
},
Mutate {
receipt: Receipt,
command: Mutation,
guarantee: Guarantee,
},
Inquire {
receipt: Receipt,
guarantee: Guarantee,
},
Retire {
receipt: Receipt,
},
}
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TableReply<Value, Outcome, Refusal> {
Read(Answer<Value, Refusal>),
Mutation(MutationAnswer<Outcome, Refusal>),
Retired(Result<(), Error>),
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum StorageFailure {
Io { raw_os_error: Option<i32> },
Codec,
Core(Error),
Locked,
UnsupportedPlatform,
Format,
Checksum,
TooLarge,
Conflict,
UnsafePath,
Truncated,
WorkerClosed,
SchemaMismatch,
}
pub struct TablePipe<Row: PersistentRow, P: TableProtocol<Row>>(PhantomData<fn() -> (Row, P)>);
impl<Row: PersistentRow, P: TableProtocol<Row>> crate::Pipe for TablePipe<Row, P> {
type In<'a> = TableRequest<P::Query, P::Mutation>;
type Out<'a> = Result<TableReply<P::Value, P::Outcome, P::Refusal>, StorageFailure>;
}