use std::pin::Pin;
use entelix_core::stream::StreamDelta;
use futures::Stream;
pub type BoxStream<'a, T> = Pin<Box<dyn Stream<Item = T> + Send + 'a>>;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum StreamMode {
Values,
Updates,
Messages,
Debug,
Events,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum StreamChunk<O> {
Value(O),
Update {
node: String,
value: O,
},
Message(StreamDelta),
Debug(DebugEvent),
Event(RunnableEvent),
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum DebugEvent {
NodeStart {
node: String,
step: usize,
},
NodeEnd {
node: String,
step: usize,
},
Final,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum RunnableEvent {
Started {
name: String,
},
Finished {
name: String,
ok: bool,
},
}
impl<O> StreamChunk<O> {
pub const fn output(&self) -> Option<&O> {
match self {
Self::Value(v) | Self::Update { value: v, .. } => Some(v),
_ => None,
}
}
pub fn into_output(self) -> Option<O> {
match self {
Self::Value(v) | Self::Update { value: v, .. } => Some(v),
_ => None,
}
}
}