Struct winver::WindowsVersion

source ·
pub struct WindowsVersion {
    pub major: u32,
    pub minor: u32,
    pub build: u32,
}
Expand description

Windows OS version.

This type implements Eq and Ord so you can easily compare two versions.

assert!(WindowsVersion::new(10, 0, 1000) < WindowsVersion::new(10, 0, 2000));

This type provides four methods to detect the OS version.

Fields§

§major: u32

Major version of Windows OS.

§minor: u32

Minor version of Windows OS.

§build: u32

Build number of Windows OS.

Implementations§

source§

impl WindowsVersion

source

pub fn from_ntdll_dll() -> Result<Self, Error>

Detect the OS version of current Windows system using RtlGetVersion function in ntdll.dll DLL.

The obtained version is accurate. And this method is faster than WindowsVersion::from_wmi_os_provider. However ntdll.dll does not always exist in your system and RtlGetVersion is a kernel-mode function.

This method loads ntdll.dll dynamically and tries to call RtlGetVersion function in it. When the dynamic call fails, this method returns an error.

source

pub fn from_wmi_os_provider() -> Result<Self, Error>

Detect the OS version of current Windows system using WMI’s Win32_OperatingSystem provider via WQL.

The obtained version is accurate. However WMI may not be available due to the process security level setting. When it is not possible to access the provider, this method returns an error.

source

pub fn from_kernel32_dll() -> Result<Self, Error>

Detect the OS version of current Windows system from kernel32.dll file’s version information.

The version actually represents the OS version where the kernel32.dll file was built. The build number may be slightly different from the actual OS version. This method should be used as fallback of other methods.

This method was implemented referring to Python’s sys.getwindowsversion implementation.

source

pub fn from_get_version_ex() -> Result<Self, Error>

Detect the OS version of current Windows system using GetVersionEx Win32 API.

You need to embed a compatibility manifest into your executable. Otherwise, this method always returns version 6.2 (Windows 8) even if you’re on Windows 10 or later. So this method should be used as fallback of other methods.

This behavior is a limitation of the GetVersionEx function. Please read the Remarks section of VerifyVersionInfo document.

source

pub fn detect() -> Option<Self>

Return the OS version of the current Windows system. This method tries to get the version with the following steps. When no version could not be detected on all steps, this method returns None.

  1. Try to detect the OS version with WindowsVersion::from_ntdll_dll
  2. Try to detect the OS version with WindowsVersion::from_wmi_os_provider
  3. Try to detect the OS version with WindowsVersion::from_kernel32_dll
  4. Try to detect the OS version with WindowsVersion::from_get_version_ex
source§

impl WindowsVersion

source

pub fn new(major: u32, minor: u32, build: u32) -> Self

Create WindowsVersion instance with the major, minor, and build numbers.

Trait Implementations§

source§

impl Clone for WindowsVersion

source§

fn clone(&self) -> WindowsVersion

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for WindowsVersion

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for WindowsVersion

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for WindowsVersion

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for WindowsVersion

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<WindowsVersion> for WindowsVersion

source§

fn eq(&self, other: &WindowsVersion) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<WindowsVersion> for WindowsVersion

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for WindowsVersion

source§

impl StructuralEq for WindowsVersion

source§

impl StructuralPartialEq for WindowsVersion

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.