1use core::error::Error as StdError;
2use core::fmt;
3
4use windows::Win32::System::Threading::PROCESS_INFORMATION_CLASS;
5
6pub mod process;
7
8pub const PROCESS_POWER_THROTTLING: PROCESS_INFORMATION_CLASS = PROCESS_INFORMATION_CLASS(4);
10pub(crate) const WIN11_22H2: u32 = 22621;
12
13pub enum Error {
15 NotAvailable(u32),
19 Windows(windows::core::Error),
21 WinVer(winver::Error),
23}
24
25impl fmt::Display for Error {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Error::NotAvailable(winver) => {
29 write!(f, "Power throttling API is not available in the version: {winver}")
30 }
31 Error::Windows(err) => {
32 write!(f, "Windows error: {}", err)
33 }
34 Error::WinVer(err) => {
35 write!(f, "WinVer error: {}", err)
36 }
37 }
38 }
39}
40
41impl fmt::Debug for Error {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 match self {
44 Error::NotAvailable(winver) => f.debug_tuple("NotAvailable").field(winver).finish(),
45 Error::Windows(err) => f.debug_tuple("Windows").field(err).finish(),
46 Error::WinVer(err) => f.debug_tuple("WinVer").field(err).finish(),
47 }
48 }
49}
50
51impl StdError for Error {
52 fn source(&self) -> Option<&(dyn StdError + 'static)> {
53 match self {
54 Error::NotAvailable(_) => None,
55 Error::Windows(err) => Some(err),
56 Error::WinVer(err) => Some(err),
57 }
58 }
59}
60
61impl From<windows::core::Error> for Error {
62 fn from(err: windows::core::Error) -> Self {
63 Error::Windows(err)
64 }
65}
66
67impl From<winver::Error> for Error {
68 fn from(err: winver::Error) -> Self {
69 Error::WinVer(err)
70 }
71}