use crate::progress::{Source, Target};
use crate::communication::Push;
use crate::dataflow::Scope;
use crate::dataflow::channels::pushers::tee::TeeHelper;
use crate::dataflow::channels::BundleCore;
use std::fmt::{self, Debug};
use crate::Container;
#[derive(Clone)]
pub struct StreamCore<S: Scope, D> {
name: Source,
scope: S,
ports: TeeHelper<S::Timestamp, D>,
}
pub type Stream<S, D> = StreamCore<S, Vec<D>>;
impl<S: Scope, D: Container> StreamCore<S, D> {
pub fn connect_to<P: Push<BundleCore<S::Timestamp, D>>+'static>(&self, target: Target, pusher: P, identifier: usize) {
let mut logging = self.scope().logging();
logging.as_mut().map(|l| l.log(crate::logging::ChannelsEvent {
id: identifier,
scope_addr: self.scope.addr(),
source: (self.name.node, self.name.port),
target: (target.node, target.port),
}));
self.scope.add_edge(self.name, target);
self.ports.add_pusher(pusher);
}
pub fn new(source: Source, output: TeeHelper<S::Timestamp, D>, scope: S) -> Self {
Self { name: source, ports: output, scope }
}
pub fn name(&self) -> &Source { &self.name }
pub fn scope(&self) -> S { self.scope.clone() }
}
impl<S, D> Debug for StreamCore<S, D>
where
S: Scope,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Stream")
.field("source", &self.name)
.finish()
}
}