1 use core::marker;
2 
3 
4 use stream::Stream;
5 
6 use {Async, Poll};
7 
8 
9 /// Stream that produces the same element repeatedly.
10 ///
11 /// This structure is created by the `stream::repeat` function.
12 #[derive(Debug)]
13 #[must_use = "streams do nothing unless polled"]
14 pub struct Repeat<T, E>
15     where T: Clone
16 {
17     item: T,
18     error: marker::PhantomData<E>,
19 }
20 
21 /// Create a stream which produces the same item repeatedly.
22 ///
23 /// Stream never produces an error or EOF. Note that you likely want to avoid
24 /// usage of `collect` or such on the returned stream as it will exhaust
25 /// available memory as it tries to just fill up all RAM.
26 ///
27 /// ```rust
28 /// use futures::*;
29 ///
30 /// let mut stream = stream::repeat::<_, bool>(10);
31 /// assert_eq!(Ok(Async::Ready(Some(10))), stream.poll());
32 /// assert_eq!(Ok(Async::Ready(Some(10))), stream.poll());
33 /// assert_eq!(Ok(Async::Ready(Some(10))), stream.poll());
34 /// ```
repeat<T, E>(item: T) -> Repeat<T, E> where T: Clone35 pub fn repeat<T, E>(item: T) -> Repeat<T, E>
36     where T: Clone
37 {
38     Repeat {
39         item: item,
40         error: marker::PhantomData,
41     }
42 }
43 
44 impl<T, E> Stream for Repeat<T, E>
45     where T: Clone
46 {
47     type Item = T;
48     type Error = E;
49 
poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>50     fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
51         Ok(Async::Ready(Some(self.item.clone())))
52     }
53 }
54