use super::{Guarantee, StorageFailure, SubscriptionId, TableReply, TableRequest, ViewUpdate};
use core::num::NonZeroU64;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RequestId(pub NonZeroU64);
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ContinuousRequest<Query, Mutation, View> {
Command {
id: RequestId,
request: TableRequest<Query, Mutation>,
},
Subscribe {
id: RequestId,
view: View,
guarantee: Guarantee,
},
Unsubscribe {
id: RequestId,
subscription: SubscriptionId,
},
Resynchronize {
id: RequestId,
subscription: SubscriptionId,
},
}
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ContinuousReply<Value, Outcome, Refusal, Id, Projection> {
ReplicationInterrupted {
failure: StorageFailure,
},
SubscriptionRefused {
id: RequestId,
reason: SubscriptionRefusal,
},
Command {
id: RequestId,
reply: Result<TableReply<Value, Outcome, Refusal>, StorageFailure>,
},
Subscribed {
id: RequestId,
subscription: SubscriptionId,
},
Unsubscribed {
id: RequestId,
subscription: SubscriptionId,
},
Resynchronizing {
id: RequestId,
subscription: SubscriptionId,
},
View {
subscription: SubscriptionId,
update: ViewUpdate<Id, Projection>,
},
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SubscriptionRefusal {
Full,
Unknown,
Exhausted,
Unavailable(super::Error),
}
pub struct ContinuousPipe<Row, Protocol>(core::marker::PhantomData<fn() -> (Row, Protocol)>);
impl<Row: super::PersistentRow, Protocol: super::ViewProtocol<Row>> crate::Pipe
for ContinuousPipe<Row, Protocol>
{
type In<'a> = ContinuousRequest<Protocol::Query, Protocol::Mutation, Protocol::View>;
type Out<'a> = ContinuousReply<
Protocol::Value,
Protocol::Outcome,
Protocol::Refusal,
Row::Id,
<Protocol::View as crate::storage::warp_table::observed::ViewDefinition<Row>>::Value,
>;
}