1 use bytes::Buf;
2 use futures::Poll;
3 use std::error::Error;
4 use std::fmt;
5 use BufStream;
6
7 /// Converts an `Iterator` into a `BufStream` which is always ready to yield the
8 /// next value.
9 ///
10 /// Iterators in Rust don't express the ability to block, so this adapter
11 /// simply always calls `iter.next()` and returns that.
iter<I>(i: I) -> Iter<I::IntoIter> where I: IntoIterator, I::Item: Buf,12 pub fn iter<I>(i: I) -> Iter<I::IntoIter>
13 where
14 I: IntoIterator,
15 I::Item: Buf,
16 {
17 Iter {
18 iter: i.into_iter(),
19 }
20 }
21
22 /// `BufStream` returned by the [`iter`] function.
23 #[derive(Debug)]
24 pub struct Iter<I> {
25 iter: I,
26 }
27
28 #[derive(Debug)]
29 pub enum Never {}
30
31 impl<I> BufStream for Iter<I>
32 where
33 I: Iterator,
34 I::Item: Buf,
35 {
36 type Item = I::Item;
37 type Error = Never;
38
poll_buf(&mut self) -> Poll<Option<Self::Item>, Self::Error>39 fn poll_buf(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
40 Ok(self.iter.next().into())
41 }
42 }
43
44 impl fmt::Display for Never {
fmt(&self, _: &mut fmt::Formatter) -> fmt::Result45 fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
46 unreachable!();
47 }
48 }
49
50 impl Error for Never {
description(&self) -> &str51 fn description(&self) -> &str {
52 unreachable!();
53 }
54 }
55