Skip to main content

MessageWriter

Trait MessageWriter 

Source
pub trait MessageWriter: Send + 'static {
    // Required methods
    fn send(
        &mut self,
        bytes: Bytes,
    ) -> impl Future<Output = Result<(), TransportError>> + Send;
    fn flush(
        &mut self,
    ) -> impl Future<Output = Result<(), TransportError>> + Send;
    fn close(
        &mut self,
    ) -> impl Future<Output = Result<(), TransportError>> + Send;
}
Expand description

通用连接、Session、请求和事件契约;与独立 Vendor 绑定使用相同运行时。 完整文本消息传输契约。 唯一 Writer owner 操作的写边界;不得在等待时阻挡 Reader。

Required Methods§

Source

fn send( &mut self, bytes: Bytes, ) -> impl Future<Output = Result<(), TransportError>> + Send

接受完整文本消息;成功不证明远端接收,资源可保持到 flush。

async fn write<W: ydp_core::MessageWriter>(writer: &mut W) { let _ = writer.send(bytes::Bytes::from_static(b"{}")).await; }
Source

fn flush(&mut self) -> impl Future<Output = Result<(), TransportError>> + Send

推进已接受数据;成功不证明远端执行。

async fn flush<W: ydp_core::MessageWriter>(writer: &mut W) { let _ = writer.flush().await; }
Source

fn close(&mut self) -> impl Future<Output = Result<(), TransportError>> + Send

开始传输关闭;核心同时推进 Reader,终结时允许销毁两半。

async fn close<W: ydp_core::MessageWriter>(writer: &mut W) { let _ = writer.close().await; }

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§