Skip to main content

commonware_p2p/authenticated/
mailbox.rs

1use commonware_actor::mailbox;
2use commonware_runtime::Metrics;
3use std::num::NonZeroUsize;
4
5/// A mailbox wraps a sender for messages of type `T`.
6#[derive(Debug)]
7pub struct Mailbox<T: mailbox::UnreliablePolicy>(pub(crate) mailbox::UnreliableSender<T>);
8
9impl<T: mailbox::UnreliablePolicy> Mailbox<T> {
10    /// Returns a new mailbox with the given sender.
11    pub fn new(
12        metrics: impl Metrics,
13        size: NonZeroUsize,
14    ) -> (Self, mailbox::UnreliableReceiver<T>) {
15        let (sender, receiver) = mailbox::new_unreliable(metrics, size);
16        (Self(sender), receiver)
17    }
18}
19
20impl<T: mailbox::UnreliablePolicy> Clone for Mailbox<T> {
21    fn clone(&self) -> Self {
22        Self(self.0.clone())
23    }
24}