@@ -22,8 +22,8 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
22
22
/// so it can be used in FFI in places where a handle is passed as an argument,
23
23
/// it is not captured or consumed, and it is never null.
24
24
///
25
- /// Note that it *may* have the value `INVALID_HANDLE_VALUE`. See [here] for
26
- /// the full story.
25
+ /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
26
+ /// sometimes a valid handle value. See [here] for the full story.
27
27
///
28
28
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
29
29
#[ derive( Copy , Clone ) ]
@@ -42,10 +42,10 @@ pub struct BorrowedHandle<'handle> {
42
42
/// so it can be used in FFI in places where a handle is passed as a consumed
43
43
/// argument or returned as an owned value, and is never null.
44
44
///
45
- /// Note that it *may* have the value `INVALID_HANDLE_VALUE`. See [here] for
46
- /// the full story. For APIs like `CreateFileW` which report errors with
47
- /// `INVALID_HANDLE_VALUE` instead of null, use [`OptionFileHandle`] instead
48
- /// of `Option<OwnedHandle>`.
45
+ /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
46
+ /// sometimes a valid handle value. See [here] for the full story. For APIs
47
+ /// like `CreateFileW` which report errors with `INVALID_HANDLE_VALUE` instead
48
+ /// of null, use [`OptionFileHandle`] instead of `Option<OwnedHandle>`.
49
49
///
50
50
/// `OwnedHandle` uses [`CloseHandle`] to close its handle on drop. As such,
51
51
/// it must not be used with handles to open registry keys which need to be
@@ -98,8 +98,14 @@ impl BorrowedHandle<'_> {
98
98
///
99
99
/// # Safety
100
100
///
101
- /// The resource pointed to by `handle` must remain open for the duration
102
- /// of the returned `BorrowedHandle`, and it must not be null.
101
+ /// The resource pointed to by `handle` must be a valid open handle, it
102
+ /// must remain open for the duration of the returned `BorrowedHandle`, and
103
+ /// it must not be null.
104
+ ///
105
+ /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
106
+ /// sometimes a valid handle value. See [here] for the full story.
107
+ ///
108
+ /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
103
109
#[ inline]
104
110
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
105
111
pub unsafe fn borrow_raw_handle ( handle : RawHandle ) -> Self {
@@ -182,6 +188,9 @@ impl IntoRawHandle for OwnedHandle {
182
188
impl FromRawHandle for OwnedHandle {
183
189
/// Constructs a new instance of `Self` from the given raw handle.
184
190
///
191
+ /// Use `OptionFileHandle` instead of `Option<OwnedHandle>` for APIs that
192
+ /// use `INVALID_HANDLE_VALUE` to indicate failure.
193
+ ///
185
194
/// # Safety
186
195
///
187
196
/// The resource pointed to by `handle` must be open and suitable for
@@ -191,7 +200,11 @@ impl FromRawHandle for OwnedHandle {
191
200
/// In particular, it must not be used with handles to open registry
192
201
/// keys which need to be closed with [`RegCloseKey`] instead.
193
202
///
203
+ /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
204
+ /// sometimes a valid handle value. See [here] for the full story.
205
+ ///
194
206
/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
207
+ /// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
195
208
#[ inline]
196
209
unsafe fn from_raw_handle ( handle : RawHandle ) -> Self {
197
210
assert ! ( !handle. is_null( ) ) ;
@@ -200,14 +213,19 @@ impl FromRawHandle for OwnedHandle {
200
213
}
201
214
202
215
impl FromRawHandle for OptionFileHandle {
203
- /// Constructs a new instance of `Self` from the given raw handle.
216
+ /// Constructs a new instance of `Self` from the given raw handle returned
217
+ /// from a Windows API that uses `INVALID_HANDLE_VALUE` to indicate
218
+ /// failure, such as `CreateFileW`.
219
+ ///
220
+ /// Use `Option<OwnedHandle>` instead of `OptionFileHandle` for APIs that
221
+ /// use null to indicate failure.
204
222
///
205
223
/// # Safety
206
224
///
207
225
/// The resource pointed to by `handle` must be either open and otherwise
208
- /// unowned, or equal to `INVALID_HANDLE_VALUE``. Note that not all Windows
209
- /// APIs use `INVALID_HANDLE_VALUE` for errors; see [here] for the full
210
- /// story.
226
+ /// unowned, or equal to `INVALID_HANDLE_VALUE` (-1). It must not be null.
227
+ /// Note that not all Windows APIs use `INVALID_HANDLE_VALUE` for errors;
228
+ /// see [here] for the full story.
211
229
///
212
230
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
213
231
#[ inline]
0 commit comments