async_uninet/
incoming.rs

1use std::pin::Pin;
2use async_std::task::{Context, Poll};
3use async_std::stream;
4use async_std::io;
5use async_std::net;
6#[cfg(unix)]
7use async_std::os::unix::net as unix;
8use crate::Stream;
9
10#[derive(Debug)]
11pub enum Incoming<'a> {
12    Inet(net::Incoming<'a>),
13    #[cfg(unix)]
14    Unix(unix::Incoming<'a>)
15}
16
17impl<'a> From<net::Incoming<'a>> for Incoming<'a> {
18    fn from(s: net::Incoming<'_>) -> Incoming {
19        Incoming::Inet(s)
20    }
21}
22
23#[cfg(unix)]
24impl<'a> From<unix::Incoming<'a>>for Incoming<'a> {
25    fn from(s: unix::Incoming<'_>) -> Incoming {
26        Incoming::Unix(s)
27    }
28}
29
30impl<'a> stream::Stream for Incoming<'a> {
31    type Item = io::Result<Stream>;
32
33    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
34        match Pin::into_inner(self) {
35            Incoming::Inet(ref mut s) => {
36                Pin::new(s).poll_next(cx).map(|opt| opt.map(|res| res.map(Stream::Inet)))
37            }
38            #[cfg(unix)]
39            Incoming::Unix(ref mut s) => {
40                Pin::new(s).poll_next(cx).map(|opt| opt.map(|res| res.map(Stream::Unix)))
41            }
42        }
43    }
44}