Skip to main content

Listener

Trait Listener 

pub trait Listener: Send + 'static {
    type Io: AsyncRead + AsyncWrite + Unpin + Send + 'static;
    type Addr: Send;

    // Required methods
    fn accept(&mut self) -> impl Future<Output = (Self::Io, Self::Addr)> + Send;
    fn local_addr(&self) -> Result<Self::Addr, Error>;
}
Expand description

Types that can listen for connections.

Required Associated Types§

type Io: AsyncRead + AsyncWrite + Unpin + Send + 'static

The listener’s IO type.

type Addr: Send

The listener’s address type.

Required Methods§

fn accept(&mut self) -> impl Future<Output = (Self::Io, Self::Addr)> + Send

Accept a new incoming connection to this listener.

If the underlying accept call can return an error, this function must take care of logging and retrying.

fn local_addr(&self) -> Result<Self::Addr, Error>

Returns the local address that this listener is bound to.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl Listener for TcpListener

§

type Io = TcpStream

§

type Addr = SocketAddr

§

async fn accept( &mut self, ) -> (<TcpListener as Listener>::Io, <TcpListener as Listener>::Addr)

§

fn local_addr(&self) -> Result<<TcpListener as Listener>::Addr, Error>

§

impl Listener for UnixListener

Available on Unix only.
§

type Io = UnixStream

§

type Addr = SocketAddr

§

async fn accept( &mut self, ) -> (<UnixListener as Listener>::Io, <UnixListener as Listener>::Addr)

§

fn local_addr(&self) -> Result<<UnixListener as Listener>::Addr, Error>

Implementors§

§

impl<L, F> Listener for TapIo<L, F>
where L: Listener, F: FnMut(&mut <L as Listener>::Io) + Send + 'static,

§

type Io = <L as Listener>::Io

§

type Addr = <L as Listener>::Addr