[][src]Trait rsntp::ToServerAddrs

pub trait 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

Implementations on Foreign Types

impl ToServerAddrs for SocketAddr[src]

type Return = SocketAddr

impl ToServerAddrs for SocketAddrV4[src]

type Return = SocketAddrV4

impl ToServerAddrs for SocketAddrV6[src]

type Return = SocketAddrV6

impl ToServerAddrs for IpAddr[src]

type Return = (IpAddr, u16)

impl ToServerAddrs for (IpAddr, u16)[src]

type Return = (IpAddr, u16)

impl ToServerAddrs for Ipv4Addr[src]

type Return = (Ipv4Addr, u16)

impl ToServerAddrs for (Ipv4Addr, u16)[src]

type Return = (Ipv4Addr, u16)

impl ToServerAddrs for Ipv6Addr[src]

type Return = (Ipv6Addr, u16)

impl ToServerAddrs for (Ipv6Addr, u16)[src]

type Return = (Ipv6Addr, u16)

impl ToServerAddrs for str[src]

type Return = String

impl ToServerAddrs for String[src]

type Return = String

impl<'a> ToServerAddrs for (&'a str, u16)[src]

type Return = (&'a str, u16)

impl ToServerAddrs for (String, u16)[src]

type Return = String

impl<T: ToServerAddrs + ?Sized, '_> ToServerAddrs for &'_ T[src]

type Return = T::Return

Loading content...

Implementors

Loading content...