dittolive-ditto 4.9.3

Ditto is a peer to peer cross-platform database that allows mobile, web, IoT and server apps to sync with or without an internet connection.
Documentation
use super::*;
/// Builder for sending a message to a remote peer.
///
/// This builder can be constructed via [`Stream::message`].
#[derive(Clone, Copy)]
pub struct MessageBuilder<Message, Sender> {
    pub(crate) sender: Sender,
    pub(crate) message: Message,
}

impl<Payload: IntoPayload> MessageBuilder<Payload, &'_ bus::Stream> {
    /// Convert the message into a [`Bytes`] buffer and send it.
    ///
    /// # Errors
    /// If conversion failed.
    pub fn try_send(self) -> Result<SendHandle, Payload::Error> {
        Ok(SendHandle {
            handle: self.sender.inner.send(self.message.into_payload()?),
        })
    }

    /// Convert the message into a [`Bytes`] buffer infallibly and send it.
    pub fn send(self) -> SendHandle
    where
        Payload: IntoPayload<Error = core::convert::Infallible>,
    {
        self.try_send().unwrap()
    }
}