rnotifylib/destination/kinds/
rust_receiver.rs1use std::error::Error;
2use std::sync::mpsc::Sender;
3use serde::{Deserialize, Deserializer, Serialize, Serializer};
4use crate::destination::MessageDestination;
5use crate::message::Message;
6
7#[derive(Debug, Clone)]
8pub struct RustReceiverDestination {
9 sender: Sender<Message>
10}
11
12impl RustReceiverDestination {
13 pub fn create(sender: Sender<Message>) -> Self {
14 Self {
15 sender,
16 }
17 }
18}
19
20
21impl MessageDestination for RustReceiverDestination {
22 fn send(&self, message: &Message) -> Result<(), Box<dyn Error>> {
23 self.sender.send(message.clone())?;
24 Ok(())
25 }
26}
27
28impl Serialize for RustReceiverDestination {
29 fn serialize<S>(&self, _: S) -> Result<S::Ok, S::Error> where S: Serializer {
30 panic!("Not possible - testing only.")
31 }
32}
33
34impl<'de> Deserialize<'de> for RustReceiverDestination {
35 fn deserialize<D>(_: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
36 panic!("Not possible - testing only")
37 }
38}
39
40impl PartialEq for RustReceiverDestination {
41 fn eq(&self, _other: &Self) -> bool {
42 return false;
43 }
44}