Skip to main content

split_host_port_opt

Function split_host_port_opt 

Source
pub fn split_host_port_opt(
    endpoint: &str,
) -> Result<(String, Option<u16>), EndpointError>
Expand description

Split a host:port endpoint, leaving the port None when none was written.

A bracketed IPv6 literal carries colons of its own, so only a colon after the closing bracket separates the port; the brackets are stripped, because that is the form the adapters resolve. An unbracketed IPv6 literal cannot carry a port at all — brackets are what add one — so every colon in it belongs to the address.

A port that is written but is not one is an error, never a silent fallback: dialing a different service is worse than not dialing.