47 stable releases

1.9.2 Feb 22, 2024
1.9.1 Feb 20, 2024
1.6.4 Jan 31, 2024
1.0.5 Dec 26, 2023
0.1.6 Nov 30, 2023

#148 in Operating systems

Download history 6/week @ 2023-12-18 38/week @ 2023-12-25 99/week @ 2024-01-01 34/week @ 2024-01-15 63/week @ 2024-01-22 26/week @ 2024-01-29 14/week @ 2024-02-05 610/week @ 2024-02-19 104/week @ 2024-02-26 3/week @ 2024-03-04 4/week @ 2024-03-11 839/week @ 2024-04-01

843 downloads per month

MIT license

14KB
331 lines

A simple Rust crate for host discovery

Make more decisions based on the characteristics of the environment your code runs in.

  • Basic Usage
use host_discovery::{Environment, CrossPlatform, LinuxSystem};

fn main() {
    let env = Environment::new();
    
    let os = env.get_os();
    let distro = env.get_distro();
    let arch = env.get_arch();
    println!("OS: {}, Linux Distribution: {}, Arch: {}", os, distro, arch);
}
  • API Methods

trait CrossPlatform

  • fn get_os: Returns a variant of OperatingSystem
  • fn get_arch: Returns a variant of Architecture
  • fn get_cpu_cores: Returns a u32 representing the number of physical cores on the CPU
  • fn get_gpu_model: Returns an optional String Option<String> containing the GPU model
  • fn get_public_ip: Returns String containing the public ip address

trait LinuxSystem

  • fn cpuinfo_model: Returns a String containing the name of the CPU model
  • fn get_distro: Returns a String containing the name of the running Linux distribution
  • fn get_cpe_name: Returns a String containing the common platform enum
  • fn get_hostname: Returns a String containing the hostname of the machine
  • fn is_subsystem_env: Returns a boolean based on whether the Linux environment is a Windows subsystem

trait WindowsSystem

  • fn get_edition: Returns a String containing the Windows edition via the registry
  • fn get_win_hostname: Returns a String containing the hostname of the machine
  • fn get_cpu_model: Returns a String containing the CPU model via the Windows registry

Add to your project

    cargo add host_discovery

Planned Features

  • GPU enumeration & extended device detection (CPU, etc.).
  • FreeBSD, MacOS, and extended Windows support

If you experience any bugs, please don't hesitate to create an issue; so they may be fixed in a timely fashion.

Dependencies

~6–45MB
~694K SLoC