1extern crate cpuid;
4#[macro_use]
5extern crate quick_error;
6extern crate semver;
7
8#[cfg(unix)]
9mod unix;
10
11#[cfg(unix)]
12use unix::{PlatformError, total_memory};
13#[cfg(unix)]
14pub use unix::os;
15
16#[cfg(windows)]
17mod windows;
18
19#[cfg(windows)]
20use windows::{PlatformError, total_memory};
21#[cfg(windows)]
22pub use windows::os;
23
24use semver::{SemVerError, Version};
25use std::{io, result};
26use std::error::Error as ErrorTrait;
27
28pub struct OSVersion {
30 pub name: String,
32 pub version: Version,
35
36 #[cfg(unix)]
37 pub distribution: String,
39
40 #[cfg(windows)]
41 pub service_pack_version: Version,
43}
44
45pub struct Platform {
47 pub cpu: String,
50 pub cpu_vendor: String,
52
53 pub memory: u64,
55}
56
57quick_error! {
58 #[derive(Debug)]
59 pub enum Error {
60 PlatformError(err: PlatformError) {
61 from()
62 description(err.description())
63 display("{}", err)
64 }
65
66 IO(err: io::Error) {
67 from()
68 description(err.description())
69 display(s) -> ("{}: {}", s.description(), err)
70 }
71
72 SemVer(err: SemVerError) {
73 from()
74 description(err.description())
75 display(s) -> ("{}: {}", s.description(), err)
76 }
77
78 String(err: String) {
79 from()
80 description(err)
81 display("{}", err)
82 }
83 }
84}
85
86pub type Result<T> = result::Result<T, Error>;
87
88pub fn platform() -> Result<Platform> {
96 let cpu = cpuid::identify()?;
97
98 Ok(Platform {
99 cpu: cpu.brand,
100 cpu_vendor: cpu.vendor,
101
102 memory: total_memory(),
103 })
104}