use futures::channel::mpsc; /// A mailbox wraps a sender for messages of type `T`. #[derive(Debug)] pub struct Mailbox(pub(crate) mpsc::Sender); impl Mailbox { /// Returns a new mailbox with the given sender. pub fn new(size: usize) -> (Self, mpsc::Receiver) { let (sender, receiver) = mpsc::channel(size); (Self(sender), receiver) } } impl Clone for Mailbox { fn clone(&self) -> Self { Self(self.0.clone()) } } /// A mailbox wraps an unbounded sender for messages of type `T`. #[derive(Debug)] pub struct UnboundedMailbox(pub(crate) mpsc::UnboundedSender); impl UnboundedMailbox { /// Returns a new mailbox with the given sender. pub fn new() -> (Self, mpsc::UnboundedReceiver) { let (sender, receiver) = mpsc::unbounded(); (Self(sender), receiver) } } impl Clone for UnboundedMailbox { fn clone(&self) -> Self { Self(self.0.clone()) } }