| 1 |
# hostname |
| 2 |
|
| 3 |
[](https://crates.io/crates/hostname) |
| 4 |
[](https://docs.rs/hostname) |
| 5 |
[](https://github.com/djc/hostname/actions) |
| 6 |
 |
| 7 |
 |
| 8 |
 |
| 9 |
|
| 10 |
> Cross-platform system's host name functions in Rust |
| 11 |
|
| 12 |
## Supported platforms |
| 13 |
|
| 14 |
- [POSIX-compliant](https://en.wikipedia.org/wiki/POSIX#POSIX-oriented_operating_systems) systems\ |
| 15 |
(Linux, macOS, Android, FreeBSD, OpenBSD, NetBSD, Solaris, Redox, and so on) |
| 16 |
- Windows |
| 17 |
|
| 18 |
## Rust version requirements |
| 19 |
|
| 20 |
Since version `0.4.0` this crate requires Rust version `1.74` or greater. |
| 21 |
|
| 22 |
This version is explicitly tested in CI |
| 23 |
and may be bumped in any major or minor release as needed.\ |
| 24 |
Maintaining compatibility with older compilers is a priority though, |
| 25 |
so the bar for bumping the minimum supported version is set very high. |
| 26 |
Any changes to the supported minimum version will be called out in the release notes. |
| 27 |
|
| 28 |
## Usage |
| 29 |
|
| 30 |
Add the following dependency to your Cargo manifest: |
| 31 |
|
| 32 |
```toml |
| 33 |
[dependencies] |
| 34 |
hostname = "^0.4" |
| 35 |
``` |
| 36 |
|
| 37 |
Crate API provides two simple functions for retrieving and setting the system's host name: |
| 38 |
|
| 39 |
```rust |
| 40 |
use std::io; |
| 41 |
|
| 42 |
fn main() -> io::Result<()> { |
| 43 |
// Retrieve the hostname |
| 44 |
dbg!(hostname::get()?); |
| 45 |
|
| 46 |
// And set a new one |
| 47 |
hostname::set("potato")?; |
| 48 |
|
| 49 |
Ok(()) |
| 50 |
} |
| 51 |
``` |
| 52 |
|
| 53 |
## License |
| 54 |
|
| 55 |
hostname is primarily distributed under the terms of the MIT license |
| 56 |
([LICENSE](LICENSE) or https://opensource.org/license/mit). |