1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright (c) Mike Grier.
use fmt;
use io;
/// `ERROR_SUCCESS`: the code that means the call succeeded. A Win32 error code of zero is not
/// the absence of a code.
const ERROR_SUCCESS: u32 = 0;
/// A Win32 error code, exactly as Windows produced it.
///
/// The `DWORD` that `GetLastError` returns, and that a call such as `GetStorageDependencyInformation`
/// returns directly. Deliberately not an enum: the type carries whatever Windows said, including a
/// code this crate has never heard of. **It is not assumed to fit in 16 bits**: the virtdisk errors
/// are `WIN32_ERROR`s above 2^31, and `u32` holds them.
///
/// `ERROR_SUCCESS` is an ordinary value of this type, zero, and [`is_success`](Self::is_success)
/// and [`into_result`](Self::into_result) are how a call's return is turned into a `Result`.
///
/// # Example
///
/// ```
/// use win_error_codes::Win32Error;
///
/// // ERROR_FILE_NOT_FOUND.
/// let error = Win32Error::from_code(2);
/// assert_eq!(error.code(), 2);
/// assert!(!error.is_success());
///
/// // A call that returns its code directly: zero is success.
/// assert_eq!(Win32Error::from_code(0).into_result(), Ok(()));
/// assert_eq!(Win32Error::from_code(2).into_result(), Err(error));
///
/// // A code above 2^31 is carried as it is.
/// assert_eq!(Win32Error::from_code(0xC03A_0015).code(), 0xC03A_0015);
/// ```
///
/// On Windows the `io::Error` form keeps the code exactly, however large it is:
///
/// ```
/// # #[cfg(windows)] {
/// use win_error_codes::Win32Error;
///
/// // ERROR_VIRTDISK_NOT_VIRTUAL_DISK.
/// let error = Win32Error::from_code(0xC03A_0015);
/// let io_error = error.to_io_error();
///
/// assert_eq!(Win32Error::from_io(&io_error), Some(error));
/// # }
/// ```
;
/// The code in decimal and in hex, and on Windows the system's message for it after a colon.
///
/// The message is [`io::Error`]'s own rendering, which this crate does not edit: it ends with std's
/// `(os error N)`, where `N` is the code as std holds it, so a code above 2^31 appears there as a
/// negative number as well, and a code the system has no message for says so.