forked from rust-postgres/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiter.rs
More file actions
45 lines (40 loc) · 850 Bytes
/
Copy pathiter.rs
File metadata and controls
45 lines (40 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use fallible_iterator::FallibleIterator;
use futures::executor::{self, BlockingStream};
use futures::Stream;
use std::marker::PhantomData;
use std::pin::Pin;
pub struct Iter<'a, S>
where
S: Stream,
{
it: BlockingStream<Pin<Box<S>>>,
_p: PhantomData<&'a mut ()>,
}
// no-op impl to extend the borrow until drop
impl<'a, S> Drop for Iter<'a, S>
where
S: Stream,
{
fn drop(&mut self) {}
}
impl<'a, S> Iter<'a, S>
where
S: Stream,
{
pub fn new(stream: S) -> Iter<'a, S> {
Iter {
it: executor::block_on_stream(Box::pin(stream)),
_p: PhantomData,
}
}
}
impl<'a, S, T, E> FallibleIterator for Iter<'a, S>
where
S: Stream<Item = Result<T, E>>,
{
type Item = T;
type Error = E;
fn next(&mut self) -> Result<Option<T>, E> {
self.it.next().transpose()
}
}