use url::{Url}; fn parse_url(url: &str) -> Option { url.parse::() .ok() // convert to Option } pub fn get_url_host(url: &str) -> Option { parse_url(url) .and_then(|p| p.host_str().map(String::from)) }