use serde::{Deserialize, Serialize};
use std::sync::mpsc::{Receiver, Sender};
pub trait SwoPublisher {
fn start<
I: Serialize + Send + Sync + 'static,
O: Deserialize<'static> + Send + Sync + 'static,
>(
&mut self,
) -> UpdaterChannel<I, O>;
fn stop(&mut self) -> Result<(), ()>;
}
pub struct UpdaterChannel<
I: Serialize + Send + Sync + 'static,
O: Deserialize<'static> + Send + Sync + 'static,
> {
rx: Receiver<O>,
tx: Sender<I>,
}
impl<I: Serialize + Send + Sync + 'static, O: Deserialize<'static> + Send + Sync + 'static>
UpdaterChannel<I, O>
{
pub fn new(rx: Sender<I>, tx: Receiver<O>) -> Self {
Self { rx: tx, tx: rx }
}
pub fn rx(&mut self) -> &mut Receiver<O> {
&mut self.rx
}
pub fn tx(&mut self) -> &mut Sender<I> {
&mut self.tx
}
}