pub struct OsRelease { /* private fields */ }
Expand description
The parsed contents of the os-release file.
This structure is a map of the fields in the os-release file.
For more information, see os-release(5)
.
§Notes
If you are using this crate to determine the OS or a specific version of it, use the Self::id()
and Self::version_id()
methods, possibly with Self::id_like()
as fallback for Self::id()
.
When looking for an OS identification string for presentation to the user, use the Self::pretty_name()
method.
Note that operating system vendors may choose not to provide version information, for example to accommodate for rolling releases.
In this case, Self::version()
and Self::version_id()
may be None
.
Application should not rely on these fields to be set.
§Examples
Open the os-release file and print the OS name and version:
use etc_os_release::OsRelease;
let os_release = OsRelease::open()?;
println!("{}-{}", os_release.id(), os_release.version_id().unwrap_or_default());
Parse a string containing the contents of the os-release file:
use std::str::FromStr;
use etc_os_release::OsRelease;
let os_release = OsRelease::from_str(r#"
NAME=Fedora
VERSION="32 (Workstation Edition)"
ID=fedora
VERSION_ID=32
PRETTY_NAME="Fedora 32 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:32"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f32/system-administrators-guide/"
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=32
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=32
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Workstation Edition"
VARIANT_ID=workstation
"#).unwrap();
assert_eq!(os_release.id(), "fedora");
assert_eq!(os_release.version_id(), Some("32"));
Implementations§
Source§impl OsRelease
Methods to construct an OsRelease
.
impl OsRelease
Methods to construct an OsRelease
.
Sourcepub fn open() -> Result<Self, Error>
pub fn open() -> Result<Self, Error>
Open the os-release file and parse it.
If /etc/os-release
exists, it is opened.
Otherwise, /usr/lib/os-release
is opened.
If neither file exists, an error is returned.
For simplicity, this function assumes that the file is well-formed.
Sourcepub fn from_reader(reader: impl Read) -> Result<Self, Error>
pub fn from_reader(reader: impl Read) -> Result<Self, Error>
Parse the os-release file from a reader.
For simplicity, this function assumes that the file is well-formed.
Source§impl OsRelease
Methods to get any field in the os-release file.
impl OsRelease
Methods to get any field in the os-release file.
Sourcepub fn entries(&self) -> impl Iterator<Item = OsReleaseEntry<'_>>
pub fn entries(&self) -> impl Iterator<Item = OsReleaseEntry<'_>>
Returns the iterator over the fields in the os-release file.
Sourcepub fn get_value(&self, key: &str) -> Option<&str>
pub fn get_value(&self, key: &str) -> Option<&str>
Returns the value of a field in the os-release file.
Sourcepub fn get_value_as_list(&self, key: &str) -> Option<impl Iterator<Item = &str>>
pub fn get_value_as_list(&self, key: &str) -> Option<impl Iterator<Item = &str>>
Returns the value of a field in the os-release as a list of strings.
Sourcepub fn get_value_as_url(&self, key: &str) -> Result<Option<Url>, ParseError>
Available on crate feature url
only.
pub fn get_value_as_url(&self, key: &str) -> Result<Option<Url>, ParseError>
url
only.Returns the value of a field in the os-release as a URL.
Sourcepub fn get_value_as_date(
&self,
key: &str,
) -> Result<Option<NaiveDate>, ParseError>
Available on crate feature date
only.
pub fn get_value_as_date( &self, key: &str, ) -> Result<Option<NaiveDate>, ParseError>
date
only.Returns the value of a field in the os-release as a date.
Source§impl OsRelease
Methods to get general information identifying the operating system.
impl OsRelease
Methods to get general information identifying the operating system.
For more information, see the General information identifying the operating system section of os-release(5)
.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the string identifying the operating system, without a version component.
This field is suitable for presentation to the user.
If not set in the os-release file, defaults to linux
.
For more information, see the NAME=
section of os-release(5)
Sourcepub fn id(&self) -> &str
pub fn id(&self) -> &str
Returns the lower-case string identifying the operating system, excluding any version information.
This field is suitable for processing by scripts or usage in generated filenames.
If not set in the os-release file, defaults to linux
.
For more information, see the ID=
section of os-release(5)
Sourcepub fn id_like(&self) -> Option<impl Iterator<Item = &str>>
pub fn id_like(&self) -> Option<impl Iterator<Item = &str>>
Returns the list of operating system identifiers.
The list contains operating systems that are closely related to the local operating system in regards to packaging and programming interfaces. For example, the operating system that the local operating system is a derivative from.
For more information, see the ID_LIKE=
section of os-release(5)
Sourcepub fn pretty_name(&self) -> &str
pub fn pretty_name(&self) -> &str
Returns the pretty operating system name in a format suitable for presentation to the user.
If not set in the os-release file, defaults to Linux
.
For more information, see the PRETTY_NAME=
section of os-release(5)
Sourcepub fn cpe_name(&self) -> Option<&str>
pub fn cpe_name(&self) -> Option<&str>
Returns the CPE name for the operating system in URI binding syntax.
The name follows the Common Platform Enumeration Specification as proposed by the NIST.
For more information, see the CPE_NAME=
section of os-release(5)
Sourcepub fn variant(&self) -> Option<&str>
pub fn variant(&self) -> Option<&str>
Returns the string identifying a specific variant or edition of the operating system.
This field is suitable for presentation to the user.
For more information, see the VARIANT=
section of os-release(5)
§Note
This field is for display purposes only. The Self::variant_id()
field should be used for making programmatic decisions.
Sourcepub fn variant_id(&self) -> Option<&str>
pub fn variant_id(&self) -> Option<&str>
Returns the lower-case string identifying a specific variant or edition of the operating system.
For more information, see the VARIANT_ID=
section of os-release(5)
Source§impl OsRelease
Methods to get information about the version of the operating system.
impl OsRelease
Methods to get information about the version of the operating system.
For more information, see the Information about the version of the operating system section of os-release(5)
.
Sourcepub fn version(&self) -> Option<&str>
pub fn version(&self) -> Option<&str>
Returns the string identifying the operating system version, excluding any OS name information.
This field possibly includes a release code name.
This field is suitable for presentation to the user.
For more information, see the VERSION=
section of os-release(5)
Sourcepub fn version_id(&self) -> Option<&str>
pub fn version_id(&self) -> Option<&str>
Returns the lower-case string identifying the operating system version, excluding any OS name information or release code name.
This field is suitable for processing by scripts or usage in generated filenames.
For more information, see the VERSION_ID=
section of os-release(5)
Sourcepub fn version_codename(&self) -> Option<&str>
pub fn version_codename(&self) -> Option<&str>
Returns the string identifying the operating system release code name, excluding any OS name information or release code name.
This field is suitable for processing by scripts or usage in generated filenames.
For more information, see the VERSION_CODENAME=
section of os-release(5)
Sourcepub fn build_id(&self) -> Option<&str>
pub fn build_id(&self) -> Option<&str>
Returns the string uniquely identifying the system image originally used as the installation base.
For more information, see the BUILD_ID=
section of os-release(5)
Sourcepub fn image_id(&self) -> Option<&str>
pub fn image_id(&self) -> Option<&str>
Returns the lower-case string identifying a specific image of the operating system.
For more information, see the IMAGE_ID=
section of os-release(5)
Sourcepub fn image_version(&self) -> Option<&str>
pub fn image_version(&self) -> Option<&str>
Return the lower-case string identifying the OS image version.
For more information, see the IMAGE_VERSION=
section of os-release(5)
Source§impl OsRelease
Methods to get presentation information and links.
impl OsRelease
Methods to get presentation information and links.
For more information, see the Presentation information and links section of os-release(5)
.
Sourcepub fn home_url(&self) -> Result<Option<Url>, ParseError>
Available on crate feature url
only.
pub fn home_url(&self) -> Result<Option<Url>, ParseError>
url
only.Returns the URL of the homepage of the operating system, or alternatively some homepage of the specific version of the operating system.
For more information, see the HOME_URL=
section of os-release(5)
Sourcepub fn documentation_url(&self) -> Result<Option<Url>, ParseError>
Available on crate feature url
only.
pub fn documentation_url(&self) -> Result<Option<Url>, ParseError>
url
only.Returns the URL of the main documentation page of the operating system.
For more information, see the HOME_URL=
section of os-release(5)
Sourcepub fn support_url(&self) -> Result<Option<Url>, ParseError>
Available on crate feature url
only.
pub fn support_url(&self) -> Result<Option<Url>, ParseError>
url
only.Returns the URL of the main support page for the operating system.
For more information, see the HOME_URL=
section of os-release(5)
Sourcepub fn bug_report_url(&self) -> Result<Option<Url>, ParseError>
Available on crate feature url
only.
pub fn bug_report_url(&self) -> Result<Option<Url>, ParseError>
url
only.Returns the main bug reporting page for the operating system.
For more information, see the HOME_URL=
section of os-release(5)
Sourcepub fn privacy_policy_url(&self) -> Result<Option<Url>, ParseError>
Available on crate feature url
only.
pub fn privacy_policy_url(&self) -> Result<Option<Url>, ParseError>
url
only.Returns the main privacy policy page for the operating system.
For more information, see the HOME_URL=
section of os-release(5)
Sourcepub fn support_end(&self) -> Result<Option<NaiveDate>, ParseError>
Available on crate feature date
only.
pub fn support_end(&self) -> Result<Option<NaiveDate>, ParseError>
date
only.Returns the date at which support for this version of the OS ends.
For more information, see the SUPPORT_END=
section of os-release(5)
Sourcepub fn logo(&self) -> Option<&str>
pub fn logo(&self) -> Option<&str>
Returns the logo string, specifying the name of an icon as defined by freedesktop.org Icon Theme Specification.
For more information, see the LOGO=
section of os-release(5)
Sourcepub fn ansi_color(&self) -> Option<&str>
pub fn ansi_color(&self) -> Option<&str>
Returns the suggested presentation color when showing the OS name on the console.
For more information, see the ANSI_COLOR=
section of os-release(5)
Sourcepub fn vendor_name(&self) -> Option<&str>
pub fn vendor_name(&self) -> Option<&str>
Returns the name of the OS vendor.
For more information, see the VENDOR_NAME=
section of os-release(5)
Sourcepub fn vendor_url(&self) -> Result<Option<Url>, ParseError>
Available on crate feature url
only.
pub fn vendor_url(&self) -> Result<Option<Url>, ParseError>
url
only.Returns the homepage of the OS vendor.
For more information, see the VENDOR_URL=
section of os-release(5)
Source§impl OsRelease
Methods to get distribution-level defaults and metadata.
impl OsRelease
Methods to get distribution-level defaults and metadata.
For more information, see the Distribution-level defaults and metadata section of os-release(5)
.
Sourcepub fn default_hostname(&self) -> Option<&str>
pub fn default_hostname(&self) -> Option<&str>
Returns the string specifying the hostname if hostname(5)
is not present and no other configuration source specifies the hostname.
For more information, see the DEFAULT_HOSTNAME=
section of os-release(5)
Sourcepub fn architecture(&self) -> Option<&str>
pub fn architecture(&self) -> Option<&str>
Returns the string that specifies which CPU architecture the userspace binaries require.
For more information, see the ARCHITECTURE=
section of os-release(5)
Sourcepub fn sysext_level(&self) -> Option<&str>
pub fn sysext_level(&self) -> Option<&str>
Returns the lower-case string identifying the operating system extensions support level, to indicate which extension images are supported.
For more information, see the SYSEXT_LEVEL=
section of os-release(5)
Sourcepub fn confext_level(&self) -> Option<&str>
pub fn confext_level(&self) -> Option<&str>
Returns the lower-case string identifying the operating system confext support level, to indicate which confext images are supported.
For more information, see the CONFEXT_LEVEL=
section of os-release(5)
Sourcepub fn sysext_scope(&self) -> Option<impl Iterator<Item = &str>>
pub fn sysext_scope(&self) -> Option<impl Iterator<Item = &str>>
Returns the list of one or more of the strings "system"
, "initrd"
and "portable"
.
For more information, see the SYSEXT_SCOPE=
section of os-release(5)
Sourcepub fn confext_scope(&self) -> Option<impl Iterator<Item = &str>>
pub fn confext_scope(&self) -> Option<impl Iterator<Item = &str>>
Returns the list of one or more of the strings "system"
, "initrd"
and "portable"
.
For more information, see the CONFEXT_SCOPE=
section of os-release(5)
Sourcepub fn portable_prefixes(&self) -> Option<impl Iterator<Item = &str>>
pub fn portable_prefixes(&self) -> Option<impl Iterator<Item = &str>>
Returns the list of one or more valid prefix match strings for the Portable Services Documentation logic.
For more information, see the PORTABLE_PREFIXES=
section of os-release(5)