Skip to main content

Writer

Struct Writer 

Source
pub struct Writer { /* private fields */ }
Expand description

单写者句柄:可廉价克隆,所有克隆共享同一个写任务。

帧由 Writer::send 编码,因此超限帧在入队前即被拒绝。队列无界、不提供背压; 写任务因 I/O 错误退出或接收端被丢弃后,后续发送返回 runtime_unavailable。

Implementations§

Source§

impl Writer

Source

pub fn channel(max_frame_size: usize) -> (Self, UnboundedReceiver<Bytes>)

创建一个不绑定 I/O 的写句柄及其接收端,接收端得到的是不含外层长度前缀的帧数据。

主要用于测试,或由调用方自行驱动写出;生产环境使用 Writer::spawn。

Source

pub fn spawn<W: AsyncWrite + Unpin + Send + 'static>( stream: W, max_frame_size: usize, ) -> Self

启动后台写任务,把帧加上 u32 大端长度前缀后依次写入 stream。

写入失败时记录错误并结束写任务,此后所有 Writer::send 都会失败。

Source

pub fn send(&self, frame: Frame) -> Result<()>

编码并排队发送一帧,不等待实际写出。

§Errors
  • frame_too_large:编码后的帧超过 max_frame_size;
  • runtime_unavailable:写任务已结束(Python 进程已退出或连接已关闭)。

Trait Implementations§

Source§

impl Clone for Writer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.