pipecircuit 0.0.18

Correct. Robust. Fast. Portable. Pick four.
Documentation
//! The owned duplex table contract. Placement belongs to its transport.
use super::{Error, Guarantee, OperationId, PersistentRow, TableProtocol};
use core::marker::PhantomData;
/// An opaque operation identity, not a table revision or an authorization token.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Receipt(OperationId);
impl Receipt {
    /// Physical protocol construction; this is correlation, not authorization.
    #[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)]
#[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>;
}