use crate::primitives::EncodeError;
#[derive(Debug, thiserror::Error)]
pub enum Error<D> {
#[error("Producer is closed")]
Closed(Option<D>),
#[error("Producer is busy")]
Full(D),
#[error("Producer is temporarily offline")]
Offline(D),
#[error("Datum serialization error")]
Encoding(D, EncodeError),
}
impl<D: PartialEq> PartialEq for Error<D> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Closed(a), Self::Closed(b)) => a == b,
(Self::Full(a), Self::Full(b)) | (Self::Offline(a), Self::Offline(b)) => {
a == b
}
_ => false,
}
}
}
impl<D: Clone> Clone for Error<D> {
fn clone(&self) -> Self {
use serde::ser::Error as _;
match self {
Self::Closed(d) => Self::Closed(d.clone()),
Self::Full(d) => Self::Full(d.clone()),
Self::Offline(d) => Self::Offline(d.clone()),
Self::Encoding(d, e) => {
Self::Encoding(d.clone(), EncodeError::custom(e.to_string()))
}
}
}
}