Expand description
§w32-error
w32-error provides the W32Error
type for wrapping Windows API error codes. A W32Error
has
the same layout as a DWORD
, and implements Display
for printing human-readable error
messages. When the std
crate feature is enabled, W32Error
also implements Error
, and can
be converted to or from an io::Error
via the standard TryFrom
/TryInto
(io::Error
=> W32Error
) and From
/Into
(W32Error
=> io::Error
) traits.
§Examples
A W32Error
can be constructed from an arbitrary DWORD
:
ⓘ
use w32_error::W32Error;
fn main() -> Result<(), W32Error> {
Err(W32Error::new(0))
}
The W32Error::last_thread_error
method constructs a W32Error
using the last-error code set
for the calling thread:
ⓘ
use std::io;
use w32_error::W32Error;
fn windows_api_call() -> Result<(), W32Error> {
let result = SomeWindowsAPIFunction();
if result == 0 { // Zero indicates failure.
Err(W32Error::last_thread_error())
} else {
// ...
}
}
fn main() -> io::Result<()> {
windows_api_call()?; // Converts `W32Error` to `io::Error` on failure.
Ok(())
}
W32Error
implements Display
via calling FormatMessageW
:
use w32_error::W32Error;
fn main() {
let error = W32Error::new(0);
println!("{}", error);
}
Structs§
- TryFrom
IoError - A failure to convert an
io::Error
into aW32Error
. - W32Error
- A Windows API error.