use derive_new::new;
#[cfg(feature = "async")]
use std::boxed::Box;
#[cfg(feature = "async")]
use std::pin::Pin;
use std::sync::Arc;
use crate::queue::ValueAt;
use crate::time::NanoTime;
use crate::types::Element;
#[derive(new, Debug, Clone)]
pub(crate) enum Message<T: Element + Send> {
CheckPoint(NanoTime),
EndOfStream,
HistoricalValue(ValueAt<T>),
RealtimeValue(T),
HistoricalBatch(Box<[ValueAt<T>]>),
Error(Arc<anyhow::Error>),
}
impl<T: Element + Send + PartialEq> PartialEq for Message<T> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Message::CheckPoint(t1), Message::CheckPoint(t2)) => t1 == t2,
(Message::EndOfStream, Message::EndOfStream) => true,
(Message::HistoricalValue(v1), Message::HistoricalValue(v2)) => v1 == v2,
(Message::RealtimeValue(v1), Message::RealtimeValue(v2)) => v1 == v2,
(Message::HistoricalBatch(b1), Message::HistoricalBatch(b2)) => b1 == b2,
(Message::Error(_), Message::Error(_)) => false,
_ => false,
}
}
}
impl<T: Element + Send + PartialEq> Eq for Message<T> {}
#[cfg(feature = "async")]
pub trait ReceiverMessageSource<T: Element + Send> {
fn to_boxed_message_stream(self) -> Pin<Box<dyn futures::Stream<Item = Message<T>> + Send>>;
}