Skip to content

Commit 171cc82

Browse files
committed
Replace copy with clone bound
1 parent 83ff11f commit 171cc82

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/stream/cycle.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ enum CycleState {
2525
impl<S, T> Stream for Cycle<S,T>
2626
where
2727
S: Stream<Item = T>,
28-
T: Copy,
28+
T: Clone,
29+
2930
{
3031

3132
type Item = S::Item;
@@ -34,21 +35,22 @@ impl<S, T> Stream for Cycle<S,T>
3435
let this = self.project();
3536

3637
let mut next;
37-
if CycleState::FromStream == *this.state {
38+
if *this.state == CycleState::FromStream {
3839
next = futures_core::ready!(this.source.poll_next(cx));
3940

4041
if let Some(val) = next {
41-
this.buffer.push(val);
42+
this.buffer.push(val.clone());
43+
next = Some(val.clone())
4244
} else {
4345
*this.state = CycleState::FromBuffer;
44-
next = Some(this.buffer[*this.index]);
46+
next = this.buffer.get(*this.index).map(|x| x.clone());
4547
}
4648
} else {
4749
let mut index = *this.index;
4850
if index == this.buffer.len() {
4951
index = 0
5052
}
51-
next = Some(this.buffer[index]);
53+
next = Some(this.buffer[index].clone());
5254

5355
*this.index = index + 1;
5456
}
@@ -79,7 +81,7 @@ impl<S, T> Stream for Cycle<S,T>
7981
/// #
8082
/// # })
8183
/// ```
82-
pub fn cycle<S: Stream<Item = T>, T: Copy>(source: S) -> impl Stream<Item = S::Item> {
84+
pub fn cycle<S: Stream<Item = T>, T: Clone>(source: S) -> impl Stream<Item = S::Item> {
8385
Cycle {
8486
source,
8587
index: 0,

0 commit comments

Comments
 (0)