aboutsummaryrefslogtreecommitdiff
path: root/net/src/listener.rs
blob: 469f5e9a826e3b275f1a609f5e0abe0f73263066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use async_trait::async_trait;

use crate::{Conn, Endpoint, Result};

/// Alias for `Box<dyn ConnListener>`
pub type Listener<T> = Box<dyn ConnListener<Item = T>>;

/// A trait for objects which can be converted to [`Listener`].
pub trait ToListener {
    type Item;
    fn to_listener(self) -> Listener<Self::Item>;
}

/// ConnListener is a generic network listener interface for
/// [`tcp::TcpConn`], [`tls::TlsConn`], [`ws::WsConn`], and [`unix::UnixConn`].
#[async_trait]
pub trait ConnListener: Send + Sync {
    type Item;
    fn local_endpoint(&self) -> Result<Endpoint>;
    async fn accept(&self) -> Result<Conn<Self::Item>>;
}