chore: simplify ClientId::hostname

This commit is contained in:
Paolo Barbolini
2020-08-04 11:23:39 +02:00
parent 6c440bda73
commit 3e62efb46a

View File

@@ -43,18 +43,17 @@ impl ClientId {
/// Defines a `ClientId` with the current hostname, of `localhost` if hostname could not be
/// found
#[cfg(feature = "hostname")]
pub fn hostname() -> ClientId {
ClientId::Domain(
#[cfg(feature = "hostname")]
return ClientId::Domain(
hostname::get()
.map_err(|_| ())
.and_then(|s| s.into_string().map_err(|_| ()))
.unwrap_or_else(|_| DEFAULT_DOMAIN_CLIENT_ID.to_string()),
)
}
#[cfg(not(feature = "hostname"))]
pub fn hostname() -> ClientId {
ClientId::Domain(DEFAULT_DOMAIN_CLIENT_ID.to_string())
.ok()
.and_then(|s| s.into_string().ok())
.unwrap_or_else(|| DEFAULT_DOMAIN_CLIENT_ID.to_string()),
);
#[cfg(not(feature = "hostname"))]
return ClientId::Domain(DEFAULT_DOMAIN_CLIENT_ID.to_string());
}
}