@@ -22,8 +22,9 @@ 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.
24
24
///
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.
25
+ /// Note that it *may* have the value `-1`, which in `BorrowedFd` always
26
+ /// represents the current process handle, and not `INVALID_HANDLE_VALUE`,
27
+ /// despite the two having the same value. See [here] for the full story.
27
28
///
28
29
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
29
30
/// detached from processes, or when `windows_subsystem` is used.
@@ -45,8 +46,9 @@ pub struct BorrowedHandle<'handle> {
45
46
///
46
47
/// This closes the handle on drop.
47
48
///
48
- /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
49
- /// sometimes a valid handle value. See [here] for the full story.
49
+ /// Note that it *may* have the value `-1`, which in `OwnedFd` always
50
+ /// represents the current process handle, and not `INVALID_HANDLE_VALUE`,
51
+ /// despite the two having the same value. See [here] for the full story.
50
52
///
51
53
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
52
54
/// detached from processes, or when `windows_subsystem` is used.
@@ -75,11 +77,11 @@ pub struct OwnedHandle {
75
77
/// `NULL`. This ensures that such FFI calls cannot start using the handle without
76
78
/// checking for `NULL` first.
77
79
///
78
- /// This type considers any value other than `NULL` to be valid, including `INVALID_HANDLE_VALUE`.
79
- /// This is because APIs that use `NULL` as their sentry value don't treat `INVALID_HANDLE_VALUE`
80
- /// as special .
80
+ /// This type may hold any handle value that [`OwnedFd`] may hold, except `NULL`. It may
81
+ /// hold `-1`, even though `-1` has the same value as `INVALID_HANDLE_VALUE`, because in
82
+ /// `HandleOrNull`, `-1` is interpreted to mean the current process handle .
81
83
///
82
- /// If this holds a valid handle, it will close the handle on drop.
84
+ /// If this holds a non-null handle, it will close the handle on drop.
83
85
#[ repr( transparent) ]
84
86
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
85
87
#[ derive( Debug ) ]
@@ -95,11 +97,14 @@ pub struct HandleOrNull(OwnedHandle);
95
97
/// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without
96
98
/// checking for `INVALID_HANDLE_VALUE` first.
97
99
///
98
- /// This type considers any value other than `INVALID_HANDLE_VALUE` to be valid, including `NULL`.
99
- /// This is because APIs that use `INVALID_HANDLE_VALUE` as their sentry value may return `NULL`
100
- /// under `windows_subsystem = "windows"` or other situations where I/O devices are detached.
100
+ /// This type may hold any handle value that [`OwnedFd`] may hold, except `-1`. It must not
101
+ /// hold `-1`, because `-1` in `HandleOrInvalid` is interpreted to mean `INVALID_HANDLE_VALUE`.
101
102
///
102
- /// If this holds a valid handle, it will close the handle on drop.
103
+ /// This type may hold `NULL`, because APIs that use `INVALID_HANDLE_VALUE` as their sentry value
104
+ /// may return `NULL` under `windows_subsystem = "windows"` or other situations where I/O devices
105
+ /// are detached.
106
+ ///
107
+ /// If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop.
103
108
#[ repr( transparent) ]
104
109
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
105
110
#[ derive( Debug ) ]
0 commit comments