protoflow_core/
message_sender.rs

1// This is free and unencumbered software released into the public domain.
2
3//! Common methods for sending messages.
4
5use crate::{prelude::ToString, Message, PortError, PortResult};
6
7pub trait MessageSender<T: Message> {
8    /// Sends a message, blocking until it has been sent.
9    ///
10    /// Returns `Ok(())` if the message was sent.
11    /// Returns `Err(PortError::Disconnected)` if the port is disconnected.
12    /// Returns `Err(PortError::Closed)` if the port is closed.
13    /// Returns `Err(PortError)` if another error occurs.
14    fn send<'a>(&self, _message: impl Into<&'a T>) -> PortResult<()>
15    where
16        T: 'a,
17    {
18        Err(PortError::Other("not implemented".to_string()))
19    }
20
21    /// Tries to send a message, returning immediately.
22    ///
23    /// Returns `Ok(true)` if the message was sent.
24    /// Returns `Ok(false)` if the message could not be immediately sent.
25    /// Returns `Err(PortError::Disconnected)` if the port is disconnected.
26    /// Returns `Err(PortError::Closed)` if the port is closed.
27    /// Returns `Err(PortError)` if another error occurs.
28    fn try_send<'a>(&self, _message: impl Into<&'a T>) -> PortResult<bool>
29    where
30        T: 'a,
31    {
32        Err(PortError::Other("not implemented".to_string()))
33    }
34}