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