@@ -142,17 +142,17 @@ impl BorrowedHandle<'_> {
142
142
}
143
143
144
144
impl TryFrom < HandleOrNull > for OwnedHandle {
145
- type Error = ( ) ;
145
+ type Error = NotHandle ;
146
146
147
147
#[ inline]
148
- fn try_from ( handle_or_null : HandleOrNull ) -> Result < Self , ( ) > {
148
+ fn try_from ( handle_or_null : HandleOrNull ) -> Result < Self , NotHandle > {
149
149
let owned_handle = handle_or_null. 0 ;
150
150
if owned_handle. handle . is_null ( ) {
151
151
// Don't call `CloseHandle`; it'd be harmless, except that it could
152
152
// overwrite the `GetLastError` error.
153
153
forget ( owned_handle) ;
154
154
155
- Err ( ( ) )
155
+ Err ( NotHandle ( ( ) ) )
156
156
} else {
157
157
Ok ( owned_handle)
158
158
}
@@ -200,23 +200,37 @@ impl OwnedHandle {
200
200
}
201
201
202
202
impl TryFrom < HandleOrInvalid > for OwnedHandle {
203
- type Error = ( ) ;
203
+ type Error = NotHandle ;
204
204
205
205
#[ inline]
206
- fn try_from ( handle_or_invalid : HandleOrInvalid ) -> Result < Self , ( ) > {
206
+ fn try_from ( handle_or_invalid : HandleOrInvalid ) -> Result < Self , NotHandle > {
207
207
let owned_handle = handle_or_invalid. 0 ;
208
208
if owned_handle. handle == c:: INVALID_HANDLE_VALUE {
209
209
// Don't call `CloseHandle`; it'd be harmless, except that it could
210
210
// overwrite the `GetLastError` error.
211
211
forget ( owned_handle) ;
212
212
213
- Err ( ( ) )
213
+ Err ( NotHandle ( ( ) ) )
214
214
} else {
215
215
Ok ( owned_handle)
216
216
}
217
217
}
218
218
}
219
219
220
+ /// This is the error type used by [`HandleOrInvalid`] and
221
+ /// [`HandleOrNull`] when attempting to convert into a handle,
222
+ /// to indicate that the value is not a handle.
223
+ #[ unstable( feature = "io_safety" , issue = "87074" ) ]
224
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
225
+ pub struct NotHandle ( ( ) ) ;
226
+
227
+ #[ unstable( feature = "io_safety" , issue = "87074" ) ]
228
+ impl fmt:: Display for NotHandle {
229
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
230
+ "the return value of a Windows API call indicated an error" . fmt ( fmt)
231
+ }
232
+ }
233
+
220
234
impl AsRawHandle for BorrowedHandle < ' _ > {
221
235
#[ inline]
222
236
fn as_raw_handle ( & self ) -> RawHandle {
0 commit comments