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