pub fn error_code_of(error: &Error) -> Option<ErrorCode>Expand description
The code error carries, if it carries one.
Every failure the I/O ring reports answers Some, because the ring reports each as an
HRESULT; the Windows path reads it so into each IoFault it relays. An error carrying a
Win32 code, as io::Error::from_raw_os_error makes, answers it wrapped as
HRESULT_FROM_WIN32 wraps it (error_code_from_win32). An error with neither, such as one a
consumer’s provider made from a message, answers None. A code read from a
FailureCause::Provider error is the provider’s own, relayed, not one dioring captured
(DI-D-47).
use win_durable_ioring::{error_code_of, win32_code_of};
// ERROR_IO_DEVICE, as std reports a Win32 error.
let code = error_code_of(&std::io::Error::from_raw_os_error(1117)).unwrap();
assert_eq!(win32_code_of(code), Some(1117));
assert_eq!(code.hresult().cast_unsigned(), 0x8007_045D);