|
|
@ -7,15 +7,11 @@ use crate::task::{Context, Poll};
|
|
|
|
|
|
|
|
|
|
|
|
pin_project! {
|
|
|
|
pin_project! {
|
|
|
|
/// A stream that will repeatedly yield the same list of elements
|
|
|
|
/// A stream that will repeatedly yield the same list of elements
|
|
|
|
pub struct Cycle<S>
|
|
|
|
pub struct Cycle<S, T> {
|
|
|
|
where
|
|
|
|
|
|
|
|
S: Stream,
|
|
|
|
|
|
|
|
S::Item: Clone,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
#[pin]
|
|
|
|
#[pin]
|
|
|
|
source: S,
|
|
|
|
source: S,
|
|
|
|
index: usize,
|
|
|
|
index: usize,
|
|
|
|
buffer: Vec<S::Item>,
|
|
|
|
buffer: Vec<T>,
|
|
|
|
state: CycleState,
|
|
|
|
state: CycleState,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -26,12 +22,12 @@ enum CycleState {
|
|
|
|
FromBuffer,
|
|
|
|
FromBuffer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<S> Cycle<S>
|
|
|
|
impl<S> Cycle<S, S::Item>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
S: Stream,
|
|
|
|
S: Stream,
|
|
|
|
S::Item: Clone,
|
|
|
|
S::Item: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pub fn new(source: S) -> Cycle<S> {
|
|
|
|
pub fn new(source: S) -> Cycle<S, S::Item> {
|
|
|
|
Cycle {
|
|
|
|
Cycle {
|
|
|
|
source,
|
|
|
|
source,
|
|
|
|
index: 0,
|
|
|
|
index: 0,
|
|
|
@ -41,10 +37,10 @@ where
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<S> Stream for Cycle<S>
|
|
|
|
impl<S, T> Stream for Cycle<S, T>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
S: Stream,
|
|
|
|
S: Stream<Item = T>,
|
|
|
|
S::Item: Clone,
|
|
|
|
T: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
type Item = S::Item;
|
|
|
|
type Item = S::Item;
|
|
|
|
|
|
|
|
|
|
|
|