Coverage Report

Created: 2026-01-27 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.28/src/io/lines.rs
Line
Count
Source
1
use super::read_line::read_line_internal;
2
use futures_core::ready;
3
use futures_core::stream::Stream;
4
use futures_core::task::{Context, Poll};
5
use futures_io::AsyncBufRead;
6
use pin_project_lite::pin_project;
7
use std::io;
8
use std::mem;
9
use std::pin::Pin;
10
11
pin_project! {
12
    /// Stream for the [`lines`](super::AsyncBufReadExt::lines) method.
13
    #[derive(Debug)]
14
    #[must_use = "streams do nothing unless polled"]
15
    pub struct Lines<R> {
16
        #[pin]
17
        reader: R,
18
        buf: String,
19
        bytes: Vec<u8>,
20
        read: usize,
21
    }
22
}
23
24
impl<R: AsyncBufRead> Lines<R> {
25
0
    pub(super) fn new(reader: R) -> Self {
26
0
        Self { reader, buf: String::new(), bytes: Vec::new(), read: 0 }
27
0
    }
28
}
29
30
impl<R: AsyncBufRead> Stream for Lines<R> {
31
    type Item = io::Result<String>;
32
33
0
    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
34
0
        let this = self.project();
35
0
        let n = ready!(read_line_internal(this.reader, cx, this.buf, this.bytes, this.read))?;
36
0
        if n == 0 && this.buf.is_empty() {
37
0
            return Poll::Ready(None);
38
0
        }
39
0
        if this.buf.ends_with('\n') {
40
0
            this.buf.pop();
41
0
            if this.buf.ends_with('\r') {
42
0
                this.buf.pop();
43
0
            }
44
0
        }
45
0
        Poll::Ready(Some(Ok(mem::take(this.buf))))
46
0
    }
47
}