mosaik 0.3.17

A Rust runtime for building self-organizing, leaderless distributed systems.
Documentation
use crate::primitives::EncodeError;

#[derive(Debug, thiserror::Error)]
pub enum Error<D> {
	/// The producer sink is closed and cannot accept new datums.
	#[error("Producer is closed")]
	Closed(Option<D>),

	/// The producer buffer is full and cannot accept new datums at this
	/// time until some of the buffered datums are consumed and sent to consumers.
	#[error("Producer is busy")]
	Full(D),

	/// The producer is offline due to not having enough active consumers
	/// that meet its minimum subscription requirement.
	///
	/// Online conditions can be configured via the
	/// `network.streams().producer().online_when(..)`.
	///
	/// By default, producers are online when they have at least one active
	/// consumer.
	#[error("Producer is temporarily offline")]
	Offline(D),

	/// An error occurred while trying to serialize the datum.
	#[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()))
			}
		}
	}
}