跳到主要内容

WriteHalf

搜索

结构体 WriteHalf 

源代码
pub struct WriteHalf<'a>(/* 私有字段 */);
展开描述

TcpStream 的借用写半部,由 split 创建。

请注意,在此类型的 AsyncWrite 实现中,poll_shutdown 将关闭 TCP 流的写方向。

写入 WriteHalf 通常使用 AsyncWriteExt trait 上提供的便捷方法来完成。

实现§

源代码§

impl WriteHalf<'_>

源代码

pub async fn ready(&self, interest: Interest) -> Result<Ready>

等待任何所请求的就绪状态。

此函数通常与 try_write() 配合使用。它可以用来代替 writable(),以检查返回的就绪集中的 Ready::WRITABLEReady::WRITE_CLOSED 事件。

该函数可能在套接字尚未就绪时完成。这是一种误报,尝试进行操作将返回 io::ErrorKind::WouldBlock。该函数也可能返回空的 Ready 集合,因此应始终检查返回值,如果请求的状态未设置,可能需要再次等待。

此函数等价于 TcpStream::ready

§取消安全性

此方法可安全取消。一旦就绪事件发生,该方法将继续立即返回,直到通过尝试读取或写入而消费该就绪事件(失败时返回 WouldBlockPoll::Pending)。

源代码

pub async fn writable(&self) -> Result<()>

等待套接字变为可写。

此函数等价于 ready(Interest::WRITABLE),通常与 try_write() 配对使用。

§取消安全性

此方法可安全取消。一旦就绪事件发生,该方法将继续立即返回,直到通过尝试写入而消费该就绪事件(失败时返回 WouldBlockPoll::Pending)。

源代码

pub fn try_write(&self, buf: &[u8]) -> Result<usize>

尝试将缓冲区写入流,返回写入的字节数。

该函数将尝试写入 buf 的全部内容,但缓冲区可能只有部分被写入。

此函数通常与 writable() 配对使用。

§返回值

如果成功写入数据,则返回 Ok(n),其中 n 是写入的字节数。如果流未准备好写入数据,则返回 Err(io::ErrorKind::WouldBlock)

源代码

pub fn try_write_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>

尝试将多个缓冲区写入流,返回写入的字节数。

按顺序从每个缓冲区写入数据,最后读取的缓冲区可能只被部分使用。此方法的行为等效于使用串联缓冲区对 try_write() 进行单次调用。

此函数通常与 writable() 配对使用。

§返回值

如果成功写入数据,则返回 Ok(n),其中 n 是写入的字节数。如果流未准备好写入数据,则返回 Err(io::ErrorKind::WouldBlock)

源代码

pub fn peer_addr(&self) -> Result<SocketAddr>

返回此流连接到的远程地址。

源代码

pub fn local_addr(&self) -> Result<SocketAddr>

返回此流绑定的本地地址。

trait 实现§

源代码§

impl AsRef<TcpStream> for WriteHalf<'_>

源代码§

fn as_ref(&self) -> &TcpStream

将此类型转换为输入类型的共享引用(通常自动推导)。
源代码§

impl AsyncWrite for WriteHalf<'_>

源代码§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. 更多信息
源代码§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Like poll_write, except that it writes from a slice of buffers. 更多信息
源代码§

fn is_write_vectored(&self) -> bool

Determines if this writer has an efficient poll_write_vectored implementation. 更多信息
源代码§

fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>

Attempts to flush the object, ensuring that any buffered data reach their destination. 更多信息
源代码§

fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. 更多信息
源代码§

impl<'a> Debug for WriteHalf<'a>

源代码§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化器格式化此值。 更多信息

自动 trait 实现§

§

impl<'a> Freeze for WriteHalf<'a>

§

impl<'a> RefUnwindSafe for WriteHalf<'a>

§

impl<'a> Send for WriteHalf<'a>

§

impl<'a> Sync for WriteHalf<'a>

§

impl<'a> Unpin for WriteHalf<'a>

§

impl<'a> UnsafeUnpin for WriteHalf<'a>

§

impl<'a> UnwindSafe for WriteHalf<'a>

blanket 实现§

源代码§

impl<T> Any for T
where T: 'static + ?Sized,

源代码§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
源代码§

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

源代码§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
源代码§

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

源代码§

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

Mutably borrows from an owned value. 更多信息
源代码§

impl<T> From<T> for T

源代码§

fn from(t: T) -> T

原样返回参数。

源代码§

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

源代码§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换是 From<T> for U 实现选择执行的操作。

源代码§

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

源代码§

type Error = Infallible

转换出错时返回的类型。
源代码§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
源代码§

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

源代码§

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

转换出错时返回的类型。
源代码§

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

执行转换。