Skip to content

Commit 9621778

Browse files
committed
Clarify what values BorrowedHandle, OwnedHandle etc. can hold.
This ports the documentation updates from rust-lang/rust#96932.
1 parent 93735f8 commit 9621778

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/types.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ pub struct BorrowedFd<'fd> {
7070
/// so it can be used in FFI in places where a handle is passed as an argument,
7171
/// it is not captured or consumed, and it is never null.
7272
///
73-
/// Note that it *may* have the value [`INVALID_HANDLE_VALUE`]. See [here] for
74-
/// the full story.
73+
/// Note that it *may* have the value `-1`, which in `BorrowedHandle` always
74+
/// represents the current process handle, and not `INVALID_HANDLE_VALUE`,
75+
/// despite the two having the same value. See [here] for the full story.
7576
///
7677
/// This type's `.to_owned()` implementation returns another `BorrowedHandle`
7778
/// rather than an `OwnedHandle`. It just makes a trivial copy of the raw
@@ -187,8 +188,9 @@ impl OwnedFd {
187188
///
188189
/// This closes the handle on drop.
189190
///
190-
/// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
191-
/// sometimes a valid handle value. See [here] for the full story.
191+
/// Note that it *may* have the value `-1`, which in `OwnedHandle` always
192+
/// represents the current process handle, and not `INVALID_HANDLE_VALUE`,
193+
/// despite the two having the same value. See [here] for the full story.
192194
///
193195
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
194196
/// detached from processes, or when `windows_subsystem` is used.
@@ -375,11 +377,10 @@ impl OwnedSocket {
375377
/// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without
376378
/// checking for `INVALID_HANDLE_VALUE` first.
377379
///
378-
/// This type concerns any value other than `INVALID_HANDLE_VALUE` to be valid, including `NULL`.
379-
/// This is because APIs that use `INVALID_HANDLE_VALUE` as their sentry value may return `NULL`
380-
/// under `windows_subsystem = "windows"` or other situations where I/O devices are detached.
380+
/// This type may hold any handle value that [`OwnedHandle`] may hold, except that when it holds
381+
/// `-1`, that value is interpreted to mean `INVALID_HANDLE_VALUE`.
381382
///
382-
/// If this holds a valid handle, it will close the handle on drop.
383+
/// If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop.
383384
#[cfg(windows)]
384385
#[repr(transparent)]
385386
#[derive(Debug)]
@@ -395,11 +396,11 @@ pub struct HandleOrInvalid(RawHandle);
395396
/// `NULL`. This ensures that such FFI calls cannot start using the handle without
396397
/// checking for `NULL` first.
397398
///
398-
/// This type concerns any value other than `NULL` to be valid, including `INVALID_HANDLE_VALUE`.
399-
/// This is because APIs that use `NULL` as their sentry value don't treat `INVALID_HANDLE_VALUE`
400-
/// as special.
399+
/// This type may hold any handle value that [`OwnedHandle`] may hold. As with `OwnedHandle`, when
400+
/// it holds `-1`, that value is interpreted as the current process handle, and not
401+
/// `INVALID_HANDLE_VALUE`.
401402
///
402-
/// If this holds a valid handle, it will close the handle on drop.
403+
/// If this holds a non-null handle, it will close the handle on drop.
403404
#[cfg(windows)]
404405
#[repr(transparent)]
405406
#[derive(Debug)]

0 commit comments

Comments
 (0)