跳到主要内容

AsyncSeek

搜索

trait AsyncSeek 

源代码
pub trait AsyncSeek {
    // Required methods
    fn start_seek(self: Pin<&mut Self>, position: SeekFrom) -> Result<()>;
    fn poll_complete(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<u64>>;
}
展开描述

异步定位字节。

此 trait 类似于 std::io::Seek trait,但与异步任务系统集成。特别地,与 Seek::seek 不同,start_seek 方法不会阻塞调用线程。

用于处理 AsyncSeek 值的实用工具由 AsyncSeekExt 提供。

必需方法§

源代码

fn start_seek(self: Pin<&mut Self>, position: SeekFrom) -> Result<()>

尝试在流中以字节为单位 seek 到一个偏移量。

允许 seek 超出流的末尾,但行为由实现定义。

如果此函数成功返回,则作业已提交。要了解何时完成,请调用 poll_complete

§错误

如果还有另一个 seek 正在进行,此函数可能返回 io::ErrorKind::Other。为避免这种情况,建议在调用 start_seek 之前先调用 poll_complete,以确保所有挂起的 seek 都已完成。

源代码

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

等待 seek 操作完成。

如果 seek 操作成功完成,此方法返回从流开头开始的新位置。该位置稍后可与 SeekFrom::Start 一起使用。

此方法返回的位置只能在调用 start_seek 之后立即依赖。如果自调用 start_seek 以来已经通过例如读取或写入更改了位置,则返回的位置是否考虑了该位置变化是未指定的。类似地,如果从未调用过 start_seek,则 poll_complete 返回的是实际位置还是其他占位值(如 0)是未指定的。

§错误

seek 到负偏移量被视为错误。

外部类型的实现§

源代码§

impl<P> AsyncSeek for Pin<P>
where P: DerefMut, P::Target: AsyncSeek,

源代码§

fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>

源代码§

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

源代码§

impl<T: AsRef<[u8]> + Unpin> AsyncSeek for Cursor<T>

源代码§

fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>

源代码§

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

源代码§

impl<T: ?Sized + AsyncSeek + Unpin> AsyncSeek for &mut T

源代码§

fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>

源代码§

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

源代码§

impl<T: ?Sized + AsyncSeek + Unpin> AsyncSeek for Box<T>

源代码§

fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>

源代码§

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

实现者§