/// An error code value returned by most COM functions. #[repr(transparent)] #[derive(Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] #[must_use] pubstruct HRESULT(pub i32);
impl HRESULT { /// Returns [`true`] if `self` is a success code. #[inline] pubconstfn is_ok(self) -> bool { self.0 >= 0
}
/// Returns [`true`] if `self` is a failure code. #[inline] pubconstfn is_err(self) -> bool {
!self.is_ok()
}
/// Asserts that `self` is a success code. /// /// This will invoke the [`panic!`] macro if `self` is a failure code and display /// the [`HRESULT`] value for diagnostics. #[inline] #[track_caller] pubfn unwrap(self) {
assert!(self.is_ok(), "HRESULT 0x{:X}", self.0);
}
/// Creates a new `HRESULT` from the Win32 error code returned by `GetLastError()`. pubfn from_thread() -> Self { #[cfg(windows)]
{ let error = unsafe { GetLastError() }; Self::from_win32(error)
} #[cfg(not(windows))]
{
unimplemented!()
}
}
/// Maps a Win32 error code to an HRESULT value. pubconstfn from_win32(error: u32) -> Self { Self(if error as i32 <= 0 {
error
} else {
(error & 0x0000_FFFF) | (7 << 16) | 0x8000_0000
} as i32)
}
/// Maps an NT error code to an HRESULT value. pubconstfn from_nt(error: i32) -> Self { Self(if error >= 0 {
error
} else {
error | 0x1000_0000
})
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.