Trait Listener

Source
pub trait Listener {
    type Io;
    type Addr;

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

A trait for a listener: TcpListener and UnixListener.

Required Associated Types§

Source

type Io

The stream’s type of this listener.

Source

type Addr

The socket address type of this listener.

Required Methods§

Source

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

Accepts a new incoming connection from this listener.

Source

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

Returns the local address that this listener is bound to.

§Errors

An error will return if got the socket address of the local half of this connection is failed.

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§

Source§

impl Listener for TcpListener

Available on crate features http1 or http2 only.
Source§

type Io = TcpStream

Source§

type Addr = SocketAddr

Source§

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

Source§

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

Source§

impl Listener for UnixListener

Available on Unix and crate feature unix-socket only.
Source§

type Io = UnixStream

Source§

type Addr = SocketAddr

Source§

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

Source§

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

Implementors§

Source§

impl Listener for TlsListener<TcpListener, TlsAcceptor>

Available on crate feature native-tls and (crate features native-tls or rustls) only.
Source§

impl Listener for TlsListener<TcpListener, TlsAcceptor>

Available on crate feature rustls and (crate features native-tls or rustls) only.