1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/// Attempts to get the system hostname as a utf8 `String`
/// # Errors
/// Hostname is not utf8
#[cfg(feature = "alloc")]
pub fn host_name() -> Result<alloc::string::String, crate::error::Error> {
    #[allow(unused_imports)]
    use alloc::string::ToString;
    let raw = rusl::unistd::uname()?;
    Ok(raw.nodename()?.to_string())
}

#[cfg(test)]
mod tests {
    #[test]
    #[cfg(feature = "alloc")]
    fn get_host_name() {
        let host = crate::unix::host_name::host_name().unwrap();
        assert!(!host.is_empty());
    }
}