Trait ToListener
pub trait ToListener<State>{
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:8000tcp://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(or0.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§
Required Methods§
fn to_listener(self) -> Result<Self::Listener, Error>
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.