Replace copy with clone bound

poc-serde-support
Felipe Sere 5 years ago
parent 83ff11ff4c
commit 171cc82aed

@ -25,7 +25,8 @@ enum CycleState {
impl<S, T> Stream for Cycle<S,T> impl<S, T> Stream for Cycle<S,T>
where where
S: Stream<Item = T>, S: Stream<Item = T>,
T: Copy, T: Clone,
{ {
type Item = S::Item; type Item = S::Item;
@ -34,21 +35,22 @@ impl<S, T> Stream for Cycle<S,T>
let this = self.project(); let this = self.project();
let mut next; let mut next;
if CycleState::FromStream == *this.state { if *this.state == CycleState::FromStream {
next = futures_core::ready!(this.source.poll_next(cx)); next = futures_core::ready!(this.source.poll_next(cx));
if let Some(val) = next { if let Some(val) = next {
this.buffer.push(val); this.buffer.push(val.clone());
next = Some(val.clone())
} else { } else {
*this.state = CycleState::FromBuffer; *this.state = CycleState::FromBuffer;
next = Some(this.buffer[*this.index]); next = this.buffer.get(*this.index).map(|x| x.clone());
} }
} else { } else {
let mut index = *this.index; let mut index = *this.index;
if index == this.buffer.len() { if index == this.buffer.len() {
index = 0 index = 0
} }
next = Some(this.buffer[index]); next = Some(this.buffer[index].clone());
*this.index = index + 1; *this.index = index + 1;
} }
@ -79,7 +81,7 @@ impl<S, T> Stream for Cycle<S,T>
/// # /// #
/// # }) /// # })
/// ``` /// ```
pub fn cycle<S: Stream<Item = T>, T: Copy>(source: S) -> impl Stream<Item = S::Item> { pub fn cycle<S: Stream<Item = T>, T: Clone>(source: S) -> impl Stream<Item = S::Item> {
Cycle { Cycle {
source, source,
index: 0, index: 0,

Loading…
Cancel
Save