Skip to main content

mm1_core/
tap.rs

1use std::fmt;
2
3use mm1_address::address::Address;
4use mm1_address::subnet::NetAddress;
5
6use crate::envelope::Envelope;
7
8pub struct OnSend<'a> {
9    pub sent_by_addr: Address,
10    pub sent_by_net:  NetAddress,
11    pub sent_by_key:  &'a dyn fmt::Display,
12    pub sent_to_addr: Address,
13    pub envelope:     &'a Envelope,
14}
15
16pub struct OnRecv<'a> {
17    pub recv_by_addr: Address,
18    pub recv_by_net:  NetAddress,
19    pub recv_by_key:  &'a dyn fmt::Display,
20    pub envelope:     &'a Envelope,
21}
22
23pub trait MessageTap: fmt::Debug + Send + Sync + 'static {
24    fn on_send(&self, event: OnSend<'_>);
25    fn on_recv(&self, event: OnRecv<'_>);
26}
27
28#[derive(Debug)]
29pub struct NoopTap;
30
31impl MessageTap for NoopTap {
32    fn on_send(&self, _event: OnSend<'_>) {}
33
34    fn on_recv(&self, _event: OnRecv<'_>) {}
35}