diff options
Diffstat (limited to 'vendor/os_info/src/info.rs')
-rw-r--r-- | vendor/os_info/src/info.rs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/vendor/os_info/src/info.rs b/vendor/os_info/src/info.rs index 85b699330..91e6cc3cb 100644 --- a/vendor/os_info/src/info.rs +++ b/vendor/os_info/src/info.rs @@ -15,7 +15,7 @@ use super::{Bitness, Type, Version}; /// use os_info; /// /// let info = os_info::get(); -/// println!("OS information: {}", info); +/// println!("OS information: {info}"); /// ``` #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -26,11 +26,13 @@ pub struct Info { pub(crate) version: Version, /// Operating system edition. pub(crate) edition: Option<String>, - /// Operating system edition. + /// Operating system codename. pub(crate) codename: Option<String>, /// Operating system architecture in terms of how many bits compose the basic values it can deal /// with. See `Bitness` for details. pub(crate) bitness: Bitness, + /// Processor architecture. + pub(crate) architecture: Option<String>, } impl Info { @@ -47,6 +49,7 @@ impl Info { /// assert_eq!(None, info.edition()); /// assert_eq!(None, info.codename()); /// assert_eq!(Bitness::Unknown, info.bitness()); + /// assert_eq!(None, info.architecture()); /// ``` pub fn unknown() -> Self { Self { @@ -55,6 +58,7 @@ impl Info { edition: None, codename: None, bitness: Bitness::Unknown, + architecture: None, } } @@ -72,6 +76,7 @@ impl Info { /// assert_eq!(None, info.edition()); /// assert_eq!(None, info.codename()); /// assert_eq!(Bitness::Unknown, info.bitness()); + /// assert_eq!(None, info.architecture()); /// ``` pub fn with_type(os_type: Type) -> Self { Self { @@ -147,6 +152,19 @@ impl Info { pub fn bitness(&self) -> Bitness { self.bitness } + + /// Returns operating system architecture. + /// + /// # Examples + /// + /// ``` + /// use os_info::Info; + /// + /// let info = Info::unknown(); + /// assert_eq!(None, info.architecture()); + pub fn architecture(&self) -> Option<&str> { + self.architecture.as_ref().map(String::as_ref) + } } impl Default for Info { @@ -162,10 +180,10 @@ impl Display for Info { write!(f, " {}", self.version)?; } if let Some(ref edition) = self.edition { - write!(f, " ({})", edition)?; + write!(f, " ({edition})")?; } if let Some(ref codename) = self.codename { - write!(f, " ({})", codename)?; + write!(f, " ({codename})")?; } write!(f, " [{}]", self.bitness) } @@ -184,16 +202,19 @@ mod tests { assert_eq!(None, info.edition()); assert_eq!(None, info.codename()); assert_eq!(Bitness::Unknown, info.bitness()); + assert_eq!(None, info.architecture()); } #[test] fn with_type() { let types = [ Type::Redox, + Type::Alpaquita, Type::Alpine, Type::Amazon, Type::Android, Type::Arch, + Type::Artix, Type::CentOS, Type::Debian, Type::Emscripten, @@ -205,6 +226,8 @@ mod tests { Type::Manjaro, Type::Mariner, Type::NixOS, + Type::OpenCloudOS, + Type::openEuler, Type::openSUSE, Type::OracleLinux, Type::Pop, @@ -262,6 +285,14 @@ mod tests { ), ( Info { + os_type: Type::Artix, + version: Version::Rolling(None), + ..Default::default() + }, + "Artix Linux Rolling Release [unknown bitness]", + ), + ( + Info { os_type: Type::Manjaro, version: Version::Rolling(Some("2020.05.24".to_owned())), ..Default::default() @@ -299,6 +330,7 @@ mod tests { edition: Some("edition".to_owned()), codename: Some("codename".to_owned()), bitness: Bitness::X64, + architecture: Some("architecture".to_owned()), }, "Mac OS 10.2.0 (edition) (codename) [64-bit]", ), |