Trait tide_disco::app::ToListener

pub trait ToListener<State>
where State: Clone + Send + Sync + 'static,
{ type Listener: Listener<State>; // Required method fn to_listener(self) -> Result<Self::Listener, Error>; }
Expand description

ToListener represents any type that can be converted into a Listener. Any type that implements ToListener can be passed to Server::listen or added to a ConcurrentListener

§Example strings on all platforms include:

  • tcp://localhost:8000
  • tcp://0.0.0.0 (binds to port 80 by default)
  • http://localhost:8000 (http is an alias for tcp)
  • http://127.0.0.1:8000 (or 0.0.0.0, or some specific bindable ip)
  • 127.0.0.1:3000 (or any string that can be parsed as a SocketAddr)
  • [::1]:1213 (an ipv6 SocketAddr)

§Strings supported only on cfg(unix) platforms:

  • http+unix:///var/run/tide/socket (absolute path)
  • http+unix://socket (relative path)
  • http+unix://./socket.file (also relative path)
  • http+unix://../socket (relative path)

§String supported only on windows:

  • :3000 (binds to port 3000)

§Specifying multiple listeners:

To bind to any number of listeners concurrently:

app.listen(vec!["tcp://localhost:8000", "tcp://localhost:8001"]).await?;

§Multiple socket resolution

If a TCP listener resolves to multiple socket addresses, tide will bind to the first successful one. For example, on ipv4+ipv6 systems, tcp://localhost:1234 resolves both to 127.0.0.1:1234 (v4) as well as [::1]:1234 (v6). The order that these are attempted is platform-determined. To listen on all of the addresses, use

use std::net::ToSocketAddrs;
app.listen("localhost:8000".to_socket_addrs()?.collect::<Vec<_>>()).await?;

§Other implementations

See below for additional provided implementations of ToListener.

Required Associated Types§

type Listener: Listener<State>

What listener are we converting into?

Required Methods§

fn to_listener(self) -> Result<Self::Listener, Error>

Transform self into a Listener. Unless self is already bound/connected to the underlying io, converting to a listener does not initiate a connection. An Err return indicates an unsuccessful conversion to a listener, not an unsuccessful bind attempt.

Implementations on Foreign Types§

§

impl<L, State> ToListener<State> for Vec<L>
where L: ToListener<State>, State: Clone + Send + Sync + 'static,

§

type Listener = ConcurrentListener<State>

§

fn to_listener(self) -> Result<<Vec<L> as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for &str
where State: Clone + Send + Sync + 'static,

§

type Listener = ParsedListener<State>

§

fn to_listener(self) -> Result<<&str as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for &String
where State: Clone + Send + Sync + 'static,

§

type Listener = ParsedListener<State>

§

fn to_listener(self) -> Result<<&String as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for (&str, u16)
where State: Clone + Send + Sync + 'static,

§

type Listener = TcpListener<State>

§

fn to_listener( self, ) -> Result<<(&str, u16) as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for (&String, u16)
where State: Clone + Send + Sync + 'static,

§

type Listener = TcpListener<State>

§

fn to_listener( self, ) -> Result<<(&String, u16) as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for (String, u16)
where State: Clone + Send + Sync + 'static,

§

type Listener = TcpListener<State>

§

fn to_listener( self, ) -> Result<<(String, u16) as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for SocketAddr
where State: Clone + Send + Sync + 'static,

§

type Listener = TcpListener<State>

§

fn to_listener( self, ) -> Result<<SocketAddr as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for String
where State: Clone + Send + Sync + 'static,

§

type Listener = ParsedListener<State>

§

fn to_listener(self) -> Result<<String as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for TcpListener
where State: Clone + Send + Sync + 'static,

§

type Listener = TcpListener<State>

§

fn to_listener( self, ) -> Result<<TcpListener as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for UnixListener
where State: Clone + Send + Sync + 'static,

§

type Listener = UnixListener<State>

§

fn to_listener( self, ) -> Result<<UnixListener as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for PathBuf
where State: Clone + Send + Sync + 'static,

§

type Listener = UnixListener<State>

§

fn to_listener(self) -> Result<<PathBuf as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for PathBuf
where State: Clone + Send + Sync + 'static,

§

type Listener = UnixListener<State>

§

fn to_listener(self) -> Result<<PathBuf as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for TcpListener
where State: Clone + Send + Sync + 'static,

§

type Listener = TcpListener<State>

§

fn to_listener( self, ) -> Result<<TcpListener as ToListener<State>>::Listener, Error>

§

impl<State> ToListener<State> for UnixListener
where State: Clone + Send + Sync + 'static,

§

type Listener = UnixListener<State>

§

fn to_listener( self, ) -> Result<<UnixListener as ToListener<State>>::Listener, Error>

Implementors§

source§

impl<State> ToListener<State> for RateLimitListener<State>
where State: Clone + Send + Sync + 'static,

§

impl<State> ToListener<State> for Url
where State: Clone + Send + Sync + 'static,

§

type Listener = ParsedListener<State>

§

impl<State> ToListener<State> for ConcurrentListener<State>
where State: Clone + Send + Sync + 'static,

§

type Listener = ConcurrentListener<State>

§

impl<State> ToListener<State> for FailoverListener<State>
where State: Clone + Send + Sync + 'static,

§

type Listener = FailoverListener<State>