chore: use Option::map_or_else instead of an if let/else

This commit is contained in:
CosminPerRam 2023-12-11 04:00:31 +02:00
parent a4bc430868
commit 44abf6ec71

View file

@ -85,13 +85,14 @@ fn find_game(game_id: &str) -> Result<&'static Game> {
/// * `Result<IpAddr>` - On sucess returns a resolved IP address; on failure
/// returns an [Error::InvalidHostname] error.
fn resolve_ip_or_domain(host: &str, extra_options: &mut Option<ExtraRequestSettings>) -> Result<IpAddr> {
if let Ok(parsed_ip) = host.parse() {
Ok(parsed_ip)
} else {
set_hostname_if_missing(host, extra_options);
host.parse().map_or_else(
|_| {
set_hostname_if_missing(host, extra_options);
resolve_domain(host)
}
resolve_domain(host)
},
|parsed_ip| Ok(parsed_ip),
)
}
/// Resolve a domain name to one of its IP addresses (the first one returned).