use std::marker::PhantomData;
pub trait ConnectionState: private::Sealed {}
pub struct Disconnected;
pub struct Connected;
pub struct Ready;
pub struct InTransaction;
pub struct Streaming;
impl ConnectionState for Disconnected {}
impl ConnectionState for Connected {}
impl ConnectionState for Ready {}
impl ConnectionState for InTransaction {}
impl ConnectionState for Streaming {}
mod private {
pub trait Sealed {}
impl Sealed for super::Disconnected {}
impl Sealed for super::Connected {}
impl Sealed for super::Ready {}
impl Sealed for super::InTransaction {}
impl Sealed for super::Streaming {}
}
#[derive(Debug)]
pub struct StateMarker<S: ConnectionState> {
_state: PhantomData<S>,
}
impl<S: ConnectionState> StateMarker<S> {
pub(crate) fn new() -> Self {
Self {
_state: PhantomData,
}
}
}
impl<S: ConnectionState> Default for StateMarker<S> {
fn default() -> Self {
Self::new()
}
}
impl<S: ConnectionState> Clone for StateMarker<S> {
fn clone(&self) -> Self {
*self
}
}
impl<S: ConnectionState> Copy for StateMarker<S> {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ProtocolState {
AwaitingResponse,
ProcessingTokens,
Draining,
}
impl Default for ProtocolState {
fn default() -> Self {
Self::AwaitingResponse
}
}
impl ProtocolState {
#[must_use]
pub fn is_usable(&self) -> bool {
matches!(
self,
Self::AwaitingResponse | Self::ProcessingTokens | Self::Draining
)
}
#[must_use]
pub fn is_busy(&self) -> bool {
matches!(self, Self::ProcessingTokens | Self::Draining)
}
}