跳到主要内容

Lines

搜索

结构体 Lines 

Source
pub struct Lines<R> { /* private fields */ }
展开描述

AsyncBufRead 读取行。

Lines 可以通过 LinesStream 转换为 Stream

此类型通常通过 lines 方法创建。

实现§

Source§

impl<R> Lines<R>
where R: AsyncBufRead + Unpin,

Source

pub async fn next_line(&mut self) -> Result<Option<String>>

返回流中的下一行。

§Cancel safety

此方法是可取消安全的。

§示例
use tokio::io::AsyncBufReadExt;

let mut lines = my_buf_read.lines();

while let Some(line) = lines.next_line().await? {
    println!("length = {}", line.len())
}
Source

pub fn get_mut(&mut self) -> &mut R

获取底层读取器的可变引用。

Source

pub fn get_ref(&mut self) -> &R

获取底层读取器的引用。

Source

pub fn into_inner(self) -> R

解包此 Lines<R>,返回底层的读取器。

注意,内部缓冲区中任何剩余的数据都会丢失。 因此,接下来从底层读取器进行读取可能会导致数据丢失。

Source§

impl<R> Lines<R>
where R: AsyncBufRead,

Source

pub fn poll_next_line( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<Option<String>>>

轮询流中的下一行。

此方法返回:

  • Poll::Pending if the next line is not yet available.
  • Poll::Ready(Ok(Some(line))) if the next line is available.
  • Poll::Ready(Ok(None)) if there are no more lines in this stream.
  • Poll::Ready(Err(err)) if an IO error occurred while reading the next line.

当方法返回 Poll::Pending 时,传入的 Context 中的 Waker 会被调度, 以便在底层 I/O 资源上有更多字节可用时收到唤醒通知。 请注意,对 poll_next_line 的多次调用中, 只有最近一次调用传入的 Context 中的 Waker 会被调度接收唤醒。

Trait 实现§

Source§

impl<R: Debug> Debug for Lines<R>

Source§

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

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

impl<'__pin, R> Unpin for Lines<R>
where PinnedFieldsOf<__Origin<'__pin, R>>: Unpin,

自动 Trait 实现§

§

impl<R> Freeze for Lines<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Lines<R>
where R: RefUnwindSafe,

§

impl<R> Send for Lines<R>
where R: Send,

§

impl<R> Sync for Lines<R>
where R: Sync,

§

impl<R> UnsafeUnpin for Lines<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for Lines<R>
where R: UnwindSafe,

Blanket 实现§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

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

Source§

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

Mutably borrows from an owned value. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

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

Source§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换的具体行为取决于 From<T> for U 的实现方式。

Source§

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

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

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

执行转换。
Source§

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

Source§

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

转换出错时返回的类型。
Source§

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

执行转换。