acto_rs/elem/
source.rs

1use lossyq::spsc::{Sender, channel};
2use super::super::{Message, SenderName, ChannelWrapper, SenderChannelId};
3use super::wrap::source_wrap;
4
5pub trait Source {
6  type OutputValue : Send;
7  type OutputError : Send;
8
9  fn process(
10    &mut self,
11    output: &mut Sender<Message<Self::OutputValue, Self::OutputError>>,
12    stop: &mut bool);
13}
14
15pub fn new<OutputValue: Send, OutputError: Send>(
16    name            : &str,
17    output_q_size   : usize,
18    source          : Box<Source<OutputValue=OutputValue, OutputError=OutputError>+Send>)
19      -> (Box<source_wrap::SourceWrap<OutputValue, OutputError>>,
20          Box<ChannelWrapper<OutputValue, OutputError>>)
21{
22  let (output_tx, output_rx) = channel(output_q_size);
23  let name = String::from(name);
24
25  (
26    Box::new(source_wrap::new(name.clone(), source, output_tx)),
27    Box::new(
28      ChannelWrapper::SenderNotConnected(
29        SenderChannelId(0),
30        output_rx,
31        SenderName(name)
32      )
33    )
34  )
35}