Skip to main content

karyon_net/
message.rs

1//! Read/write traits over message connections.
2//!
3//! Both `FramedReader`/`FramedWriter` and `WsReader`/`WsWriter`
4//! implement these, so generic code (e.g. JSON-RPC client/server
5//! reader and writer tasks) can drive either transport.
6
7use std::future::Future;
8
9use crate::{Endpoint, Result};
10
11/// Read half of a message connection.
12pub trait MessageRx: Send + Sync {
13    type Message: Send + Sync;
14
15    /// Receive one complete message.
16    fn recv_msg(&mut self) -> impl Future<Output = Result<Self::Message>> + Send;
17
18    /// Remote peer address.
19    fn peer_endpoint(&self) -> Option<Endpoint>;
20}
21
22/// Write half of a message connection.
23pub trait MessageTx: Send + Sync {
24    type Message: Send + Sync;
25
26    /// Send one complete message.
27    fn send_msg(&mut self, msg: Self::Message) -> impl Future<Output = Result<()>> + Send;
28
29    /// Remote peer address.
30    fn peer_endpoint(&self) -> Option<Endpoint>;
31}