@@ -491,17 +491,17 @@ impl BorrowedSocket<'_> {
491
491
492
492
#[ cfg( windows) ]
493
493
impl TryFrom < HandleOrInvalid > for OwnedHandle {
494
- type Error = ( ) ;
494
+ type Error = InvalidHandleError ;
495
495
496
496
#[ inline]
497
- fn try_from ( handle_or_invalid : HandleOrInvalid ) -> Result < Self , ( ) > {
497
+ fn try_from ( handle_or_invalid : HandleOrInvalid ) -> Result < Self , InvalidHandleError > {
498
498
let raw = handle_or_invalid. 0 ;
499
499
if raw == INVALID_HANDLE_VALUE {
500
500
// Don't call `CloseHandle`; it'd be harmless, except that it could
501
501
// overwrite the `GetLastError` error.
502
502
forget ( handle_or_invalid) ;
503
503
504
- Err ( ( ) )
504
+ Err ( InvalidHandleError ( ( ) ) )
505
505
} else {
506
506
Ok ( OwnedHandle { handle : raw } )
507
507
}
@@ -510,23 +510,53 @@ impl TryFrom<HandleOrInvalid> for OwnedHandle {
510
510
511
511
#[ cfg( windows) ]
512
512
impl TryFrom < HandleOrNull > for OwnedHandle {
513
- type Error = ( ) ;
513
+ type Error = NullHandleError ;
514
514
515
515
#[ inline]
516
- fn try_from ( handle_or_null : HandleOrNull ) -> Result < Self , ( ) > {
516
+ fn try_from ( handle_or_null : HandleOrNull ) -> Result < Self , NullHandleError > {
517
517
let raw = handle_or_null. 0 ;
518
518
if raw. is_null ( ) {
519
519
// Don't call `CloseHandle`; it'd be harmless, except that it could
520
520
// overwrite the `GetLastError` error.
521
521
forget ( handle_or_null) ;
522
522
523
- Err ( ( ) )
523
+ Err ( NullHandleError ( ) )
524
524
} else {
525
525
Ok ( OwnedHandle { handle : raw } )
526
526
}
527
527
}
528
528
}
529
529
530
+ /// This is the error type used by [`HandleOrNull`] when attempting to convert
531
+ /// into a handle, to indicate that the value is null.
532
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
533
+ pub struct NullHandleError ( ( ) ) ;
534
+
535
+ impl fmt:: Display for NullHandleError {
536
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
537
+ "A HandleOrNull could not be converted to a handle because it was null" . fmt ( fmt)
538
+ }
539
+ }
540
+
541
+ impl crate :: error:: Error for NullHandleError { }
542
+
543
+ /// This is the error type used by [`HandleOrInvalid`] when attempting to
544
+ /// convert into a handle, to indicate that the value is
545
+ /// `INVALID_HANDLE_VALUE`.
546
+ #[ unstable( feature = "io_safety" , issue = "87074" ) ]
547
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
548
+ pub struct InvalidHandleError ( ( ) ) ;
549
+
550
+ #[ unstable( feature = "io_safety" , issue = "87074" ) ]
551
+ impl fmt:: Display for InvalidHandleError {
552
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
553
+ "A HandleOrInvalid could not be converted to a handle because it was INVALID_HANDLE_VALUE"
554
+ . fmt ( fmt)
555
+ }
556
+ }
557
+
558
+ impl crate :: error:: Error for InvalidHandleError { }
559
+
530
560
#[ cfg( any( unix, target_os = "wasi" ) ) ]
531
561
impl AsRawFd for BorrowedFd < ' _ > {
532
562
#[ inline]
0 commit comments