this is not easy
This commit is contained in:
parent
69b441cd39
commit
7967b95553
@ -138,32 +138,22 @@ mod std_mod {
|
|||||||
|
|
||||||
use super::MessageWithSenderId;
|
use super::MessageWithSenderId;
|
||||||
|
|
||||||
pub trait TargetedMessageSendProvider {
|
pub struct MpscMessageSenderMap<MESSAGE>(
|
||||||
type Message;
|
pub HashMap<ChannelId, mpsc::Sender<MessageWithSenderId<MESSAGE>>>,
|
||||||
fn send_message(
|
|
||||||
&self,
|
|
||||||
local_channel_id: ChannelId,
|
|
||||||
target_channel_id: ChannelId,
|
|
||||||
message: Self::Message,
|
|
||||||
) -> Result<(), GenericTargetedMessagingError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MpscMessageSenderMap<Message, SendProvider: TargetedMessageSendProvider<Message = Message>>(
|
|
||||||
pub HashMap<ChannelId, SendProvider>,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<Message, SendProvider> Default for MpscMessageSenderMap<Message, SendProvider> {
|
impl<MESSAGE> Default for MpscMessageSenderMap<MESSAGE> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(Default::default())
|
Self(Default::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message, SendProvider> MpscMessageSenderMap<Message, SendProvider> {
|
impl<MESSAGE> MpscMessageSenderMap<MESSAGE> {
|
||||||
pub fn send_message(
|
pub fn send_message(
|
||||||
&self,
|
&self,
|
||||||
local_channel_id: ChannelId,
|
local_channel_id: ChannelId,
|
||||||
target_channel_id: ChannelId,
|
target_channel_id: ChannelId,
|
||||||
message: Message,
|
message: MESSAGE,
|
||||||
) -> Result<(), GenericTargetedMessagingError> {
|
) -> Result<(), GenericTargetedMessagingError> {
|
||||||
if self.0.contains_key(&target_channel_id) {
|
if self.0.contains_key(&target_channel_id) {
|
||||||
self.0
|
self.0
|
||||||
@ -181,18 +171,18 @@ mod std_mod {
|
|||||||
pub fn add_message_target(
|
pub fn add_message_target(
|
||||||
&mut self,
|
&mut self,
|
||||||
target_id: ChannelId,
|
target_id: ChannelId,
|
||||||
message_sender: mpsc::Sender<MessageWithSenderId<Message>>,
|
message_sender: mpsc::Sender<MessageWithSenderId<MESSAGE>>,
|
||||||
) {
|
) {
|
||||||
self.0.insert(target_id, message_sender);
|
self.0.insert(target_id, message_sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MpscMessageSenderWithId<Message, SendProvider> {
|
pub struct MpscMessageSenderWithId<MESSAGE> {
|
||||||
pub local_channel_id: ChannelId,
|
pub local_channel_id: ChannelId,
|
||||||
pub message_sender_map: MpscMessageSenderMap<Message, SendProvider>,
|
pub message_sender_map: MpscMessageSenderMap<MESSAGE>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message> MpscMessageSenderWithId<Message> {
|
impl<MESSAGE> MpscMessageSenderWithId<MESSAGE> {
|
||||||
pub fn new(local_channel_id: ChannelId) -> Self {
|
pub fn new(local_channel_id: ChannelId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
local_channel_id,
|
local_channel_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user