pub struct Writer { /* private fields */ }Expand description
单写者句柄:可廉价克隆,所有克隆共享同一个写任务。
帧由 Writer::send 编码,因此超限帧在入队前即被拒绝。队列无界、不提供背压;
写任务因 I/O 错误退出或接收端被丢弃后,后续发送返回 runtime_unavailable。
Implementations§
Source§impl Writer
impl Writer
Sourcepub fn channel(max_frame_size: usize) -> (Self, UnboundedReceiver<Bytes>)
pub fn channel(max_frame_size: usize) -> (Self, UnboundedReceiver<Bytes>)
创建一个不绑定 I/O 的写句柄及其接收端,接收端得到的是不含外层长度前缀的帧数据。
主要用于测试,或由调用方自行驱动写出;生产环境使用 Writer::spawn。
Sourcepub fn spawn<W: AsyncWrite + Unpin + Send + 'static>(
stream: W,
max_frame_size: usize,
) -> Self
pub fn spawn<W: AsyncWrite + Unpin + Send + 'static>( stream: W, max_frame_size: usize, ) -> Self
启动后台写任务,把帧加上 u32 大端长度前缀后依次写入 stream。
写入失败时记录错误并结束写任务,此后所有 Writer::send 都会失败。
Trait Implementations§
Auto Trait Implementations§
impl Forget for Writer
impl Freeze for Writer
impl Move for Writer
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnsafeUnpin for Writer
impl UnwindSafe for Writer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more