Coverage Report

Created: 2025-10-10 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.31/src/io/empty.rs
Line
Count
Source
1
use futures_core::task::{Context, Poll};
2
use futures_io::{AsyncBufRead, AsyncRead};
3
use std::fmt;
4
use std::io;
5
use std::pin::Pin;
6
7
/// Reader for the [`empty()`] function.
8
#[must_use = "readers do nothing unless polled"]
9
pub struct Empty {
10
    _priv: (),
11
}
12
13
/// Constructs a new handle to an empty reader.
14
///
15
/// All reads from the returned reader will return `Poll::Ready(Ok(0))`.
16
///
17
/// # Examples
18
///
19
/// A slightly sad example of not reading anything into a buffer:
20
///
21
/// ```
22
/// # futures::executor::block_on(async {
23
/// use futures::io::{self, AsyncReadExt};
24
///
25
/// let mut buffer = String::new();
26
/// let mut reader = io::empty();
27
/// reader.read_to_string(&mut buffer).await?;
28
/// assert!(buffer.is_empty());
29
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
30
/// ```
31
0
pub fn empty() -> Empty {
32
0
    Empty { _priv: () }
33
0
}
34
35
impl AsyncRead for Empty {
36
    #[inline]
37
0
    fn poll_read(
38
0
        self: Pin<&mut Self>,
39
0
        _: &mut Context<'_>,
40
0
        _: &mut [u8],
41
0
    ) -> Poll<io::Result<usize>> {
42
0
        Poll::Ready(Ok(0))
43
0
    }
44
}
45
46
impl AsyncBufRead for Empty {
47
    #[inline]
48
0
    fn poll_fill_buf(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
49
0
        Poll::Ready(Ok(&[]))
50
0
    }
51
    #[inline]
52
0
    fn consume(self: Pin<&mut Self>, _: usize) {}
53
}
54
55
impl fmt::Debug for Empty {
56
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57
0
        f.pad("Empty { .. }")
58
0
    }
59
}