Coverage Report

Created: 2025-07-18 06:42

/rust/registry/src/index.crates.io-6f17d22bba15001f/tokio-stream-0.1.17/src/wrappers/interval.rs
Line
Count
Source (jump to first uncovered line)
1
use crate::Stream;
2
use std::pin::Pin;
3
use std::task::{Context, Poll};
4
use tokio::time::{Instant, Interval};
5
6
/// A wrapper around [`Interval`] that implements [`Stream`].
7
///
8
/// [`Interval`]: struct@tokio::time::Interval
9
/// [`Stream`]: trait@crate::Stream
10
#[derive(Debug)]
11
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
12
pub struct IntervalStream {
13
    inner: Interval,
14
}
15
16
impl IntervalStream {
17
    /// Create a new `IntervalStream`.
18
0
    pub fn new(interval: Interval) -> Self {
19
0
        Self { inner: interval }
20
0
    }
21
22
    /// Get back the inner `Interval`.
23
0
    pub fn into_inner(self) -> Interval {
24
0
        self.inner
25
0
    }
26
}
27
28
impl Stream for IntervalStream {
29
    type Item = Instant;
30
31
0
    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Instant>> {
32
0
        self.inner.poll_tick(cx).map(Some)
33
0
    }
34
35
0
    fn size_hint(&self) -> (usize, Option<usize>) {
36
0
        (usize::MAX, None)
37
0
    }
38
}
39
40
impl AsRef<Interval> for IntervalStream {
41
0
    fn as_ref(&self) -> &Interval {
42
0
        &self.inner
43
0
    }
44
}
45
46
impl AsMut<Interval> for IntervalStream {
47
0
    fn as_mut(&mut self) -> &mut Interval {
48
0
        &mut self.inner
49
0
    }
50
}