use crate::RaftTypeConfig;
use crate::StorageError;
use crate::errors::NetworkError;
use crate::errors::RPCError;
use crate::errors::ReplicationClosed;
use crate::errors::ReplicationError;
use crate::errors::Timeout;
use crate::errors::Unreachable;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(bound = ""))]
pub enum StreamingError<C: RaftTypeConfig> {
#[error(transparent)]
Closed(#[from] ReplicationClosed),
#[error(transparent)]
StorageError(#[from] StorageError<C>),
#[error(transparent)]
Timeout(#[from] Timeout<C>),
#[error(transparent)]
Unreachable(#[from] Unreachable<C>),
#[error(transparent)]
Network(#[from] NetworkError<C>),
}
impl<C: RaftTypeConfig> From<StreamingError<C>> for ReplicationError<C> {
fn from(e: StreamingError<C>) -> Self {
match e {
StreamingError::Closed(e) => ReplicationError::Closed(e),
StreamingError::StorageError(e) => ReplicationError::StorageError(e),
StreamingError::Timeout(e) => ReplicationError::RPCError(RPCError::Timeout(e)),
StreamingError::Unreachable(e) => ReplicationError::RPCError(RPCError::Unreachable(e)),
StreamingError::Network(e) => ReplicationError::RPCError(RPCError::Network(e)),
}
}
}
impl<C: RaftTypeConfig> From<RPCError<C>> for StreamingError<C> {
fn from(value: RPCError<C>) -> Self {
match value {
RPCError::Timeout(e) => StreamingError::Timeout(e),
RPCError::Unreachable(e) => StreamingError::Unreachable(e),
RPCError::Network(e) => StreamingError::Network(e),
}
}
}