heim_host/platform.rs
1use std::fmt;
2
3use heim_common::prelude::*;
4
5use crate::{sys, Arch};
6
7/// Host system information.
8///
9/// ## Provided information
10///
11/// For example, for Linux host command `uname -a` returns the following line:
12/// ```bash
13/// $ uname -a
14/// Linux tardis 5.0.5-arch1-1-ARCH #1 SMP PREEMPT Wed Mar 27 17:53:10 UTC 2019 x86_64 GNU/Linux
15/// ```
16///
17/// Information in this struct for the same host will look like this:
18/// ```text
19/// Platform {
20/// system: "Linux",
21/// release: "5.0.5-arch1-1-ARCH",
22/// version: "#1 SMP PREEMPT Wed Mar 27 17:53:10 UTC 2019",
23/// hostname: "tardis",
24/// architecture: X86_64,
25/// }
26/// ```
27///
28/// Windows example:
29/// ```text
30/// Platform {
31/// system: "Windows",
32/// release: "10",
33/// version: "17763",
34/// hostname: "WINDEV1905EVAL",
35/// architecture: X86_64,
36/// }
37/// ```
38pub struct Platform(sys::Platform);
39
40wrap!(Platform, sys::Platform);
41
42impl Platform {
43 /// Returns system name.
44 pub fn system(&self) -> &str {
45 self.as_ref().system()
46 }
47
48 /// Returns system release.
49 pub fn release(&self) -> &str {
50 self.as_ref().release()
51 }
52
53 /// Returns system version.
54 pub fn version(&self) -> &str {
55 self.as_ref().version()
56 }
57
58 /// Returns system hostname.
59 pub fn hostname(&self) -> &str {
60 self.as_ref().hostname()
61 }
62
63 /// Returns system architecture.
64 pub fn architecture(&self) -> Arch {
65 self.as_ref().architecture()
66 }
67}
68
69impl fmt::Debug for Platform {
70 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71 f.debug_struct("Platform")
72 .field("system", &self.system())
73 .field("release", &self.release())
74 .field("version", &self.version())
75 .field("hostname", &self.hostname())
76 .field("architecture", &self.architecture())
77 .finish()
78 }
79}
80
81/// Returns `Future` which resolves into [Platform] struct.
82///
83/// [Platform]: ./struct.Platform.html
84pub fn platform() -> impl Future<Output = Result<Platform>> {
85 sys::platform().map_ok(Into::into)
86}