[−][src]Trait rsntp::ToServerAddrs
A trait for objects which can be converted or resolved to one or more SocketAddr values with or without a port.
This is similar to the std::net::ToSocketAddrs
trait, but port is optional. If no port is supplied
then the user of this trait falls back to a default one.
It is implemented for almost all types ToSocketAddrs
is implemented for, plus for some addition types
where the optional port is not present ((IpAddr, u16)
, and also for simple IpAddr
). For string
implementation the port is also optional, so both <host>:<port>
and <host>
can be used.
The trait is intended to be opaque, details might change.
Examples
use rsntp::ToServerAddrs; use std::net::Ipv4Addr; fn connect<A: ToServerAddrs>(addr: A) { // connect to a server with default port 1234 } connect("127.0.0.1"); // will connect to 127.0.0.1:1234 connect("127.0.0.1:456"); // will connect to 127.0.0.1:456 connect(Ipv4Addr::new(127, 0, 0, 1)); // will connect to 127.0.0.1:1234 connect((Ipv4Addr::new(127, 0, 0, 1), 456)); // will connect to 127.0.0.1:456