use core::error::Error as StdError;
use core::fmt;
use windows::Win32::System::Threading::PROCESS_INFORMATION_CLASS;
pub mod process;
pub const PROCESS_POWER_THROTTLING: PROCESS_INFORMATION_CLASS = PROCESS_INFORMATION_CLASS(4);
pub(crate) const WIN11_22H2: u32 = 22621;
pub enum Error {
NotAvailable(u32),
Windows(windows::core::Error),
WinVer(winver::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::NotAvailable(winver) => {
write!(f, "Power throttling API is not available in the version: {winver}")
}
Error::Windows(err) => {
write!(f, "Windows error: {}", err)
}
Error::WinVer(err) => {
write!(f, "WinVer error: {}", err)
}
}
}
}
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::NotAvailable(winver) => f.debug_tuple("NotAvailable").field(winver).finish(),
Error::Windows(err) => f.debug_tuple("Windows").field(err).finish(),
Error::WinVer(err) => f.debug_tuple("WinVer").field(err).finish(),
}
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Error::NotAvailable(_) => None,
Error::Windows(err) => Some(err),
Error::WinVer(err) => Some(err),
}
}
}
impl From<windows::core::Error> for Error {
fn from(err: windows::core::Error) -> Self {
Error::Windows(err)
}
}
impl From<winver::Error> for Error {
fn from(err: winver::Error) -> Self {
Error::WinVer(err)
}
}