Skip to content

Commit

Permalink
Dissolve _impl function
Browse files Browse the repository at this point in the history
On unix our implementation is so trivial as to inline it, so just
dispatch directly in gethostname().
  • Loading branch information
swsnr committed Jul 6, 2024
1 parent 0d2bd4e commit 092cb1e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ use std::ffi::OsString;
///
/// [GetComputerNameExW]: https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getcomputernameexw
pub fn gethostname() -> OsString {
gethostname_impl()
}

#[cfg(unix)]
#[inline]
fn gethostname_impl() -> OsString {
use std::os::unix::ffi::OsStringExt;
OsString::from_vec(rustix::system::uname().nodename().to_bytes().to_vec())
#[cfg(unix)]
{
use std::os::unix::ffi::OsStringExt;
OsString::from_vec(rustix::system::uname().nodename().to_bytes().to_vec())
}
#[cfg(windows)]
{
get_computer_physical_dns_hostname()
}
}

#[cfg(windows)]
#[inline]
fn gethostname_impl() -> OsString {
fn get_computer_physical_dns_hostname() -> OsString {
use std::os::windows::ffi::OsStringExt;

// The DNS host name of the local computer. If the local computer is a node
Expand Down

0 comments on commit 092cb1e

Please sign in to comment.