Skip to main content

parse_endpoint

Function parse_endpoint 

Source
pub fn parse_endpoint(endpoint: &str) -> Option<(Ipv4Addr, u16)>
Expand description

http://192.168.7.10:8791 → the address and the port; a host name, a scheme the mesh does not speak, or a missing port is None.

use std::net::Ipv4Addr;
use majordomus_cli::mesh::firewall::parse_endpoint;

assert_eq!(parse_endpoint("http://192.168.7.10:8791"), Some((Ipv4Addr::new(192, 168, 7, 10), 8791)));
assert_eq!(parse_endpoint("http://192.168.7.10:8791/"), Some((Ipv4Addr::new(192, 168, 7, 10), 8791)));
assert_eq!(parse_endpoint("192.168.7.10:8791"), Some((Ipv4Addr::new(192, 168, 7, 10), 8791)));
assert_eq!(parse_endpoint("http://hub.example:8791"), None);
assert_eq!(parse_endpoint("http://192.168.7.10"), None);