1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::fmt::Debug;
use tokio::sync::mpsc::{self, error::SendError};
use crate::traits::Processor;
#[derive(Clone)]
pub struct Remote<P>
where
P: Processor,
{
sender: mpsc::UnboundedSender<P::Command>,
}
impl<P> Remote<P>
where
P: Processor,
{
pub fn new(sender: mpsc::UnboundedSender<P::Command>) -> Self {
Self { sender }
}
pub fn send(&self, command: P::Command) -> Result<(), SendError<P::Command>> {
self.sender.send(command)
}
pub fn remote(&self) -> Self {
Self::new(self.sender.clone())
}
}
impl<P> Debug for Remote<P>
where
P: Processor,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Remote").field("sender", &"...").finish()
}
}