Repository: GuillaumeGomez/sysinfo (language: rust)

Issue:
Use std::env::consts::ARCH for System::cpu_arch
The `std::env::consts::ARCH` constant can be used instead of computing the value for every call to the function.


Discussion / hints:
Interested into sending a PR?
> Interested into sending a PR?

Should the function fallback to `std::env::consts::ARCH` if `SystemInner::cpu_arch` returns `None`?
Sounds good to me!

Fix patch:
diff --git a/src/common/system.rs b/src/common/system.rs
index 588b8c09e..5fb82956f 100644
--- a/src/common/system.rs
+++ b/src/common/system.rs
@@ -777,8 +777,8 @@ impl System {
     ///
     /// println!("CPU Architecture: {:?}", System::cpu_arch());
     /// ```
-    pub fn cpu_arch() -> Option<String> {
-        SystemInner::cpu_arch()
+    pub fn cpu_arch() -> String {
+        SystemInner::cpu_arch().unwrap_or_else(|| std::env::consts::ARCH.to_owned())
     }
 }
 
@@ -2462,7 +2462,7 @@ mod test {
 
     #[test]
     fn check_cpu_arch() {
-        assert_eq!(System::cpu_arch().is_some(), IS_SUPPORTED_SYSTEM);
+        assert!(!System::cpu_arch().is_empty());
     }
 
     // Ensure that the CPUs frequency isn't retrieved until we ask for it.


Test patch: