Skip to content

Commit aaa1794

Browse files
committed
Update the documentation for {As,Into,From}Raw{Fd,Handle,Socket}
This ports the changes proposed in rust-lang/rust#93562 to io-lifetimes. Specifically, remove the redundant comments on `OwnedHandle::from_raw_handle` and `OwnedSocket::from_raw_socket`, and remove the `FromRawHandle` impls for `HandleOrInvalid` and `HandleOrNull`.
1 parent 12aab9f commit aaa1794

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/types.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,6 @@ impl FromRawFd for OwnedFd {
597597

598598
#[cfg(windows)]
599599
impl FromRawHandle for OwnedHandle {
600-
/// Constructs a new instance of `Self` from the given raw handle.
601-
///
602-
/// # Safety
603-
///
604-
/// The resource pointed to by `raw` must be open and suitable for assuming
605-
/// ownership.
606600
#[inline]
607601
unsafe fn from_raw_handle(handle: RawHandle) -> Self {
608602
Self { handle }
@@ -611,12 +605,6 @@ impl FromRawHandle for OwnedHandle {
611605

612606
#[cfg(windows)]
613607
impl FromRawSocket for OwnedSocket {
614-
/// Constructs a new instance of `Self` from the given raw socket.
615-
///
616-
/// # Safety
617-
///
618-
/// The resource pointed to by `raw` must be open and suitable for assuming
619-
/// ownership.
620608
#[inline]
621609
unsafe fn from_raw_socket(socket: RawSocket) -> Self {
622610
debug_assert_ne!(socket, INVALID_SOCKET as RawSocket);
@@ -625,7 +613,7 @@ impl FromRawSocket for OwnedSocket {
625613
}
626614

627615
#[cfg(windows)]
628-
impl FromRawHandle for HandleOrInvalid {
616+
impl HandleOrInvalid {
629617
/// Constructs a new instance of `Self` from the given `RawHandle` returned
630618
/// from a Windows API that uses `INVALID_HANDLE_VALUE` to indicate
631619
/// failure, such as `CreateFileW`.
@@ -635,20 +623,20 @@ impl FromRawHandle for HandleOrInvalid {
635623
///
636624
/// # Safety
637625
///
638-
/// The resource pointed to by `handle` must be either open and otherwise
639-
/// unowned, null, or equal to `INVALID_HANDLE_VALUE` (-1). Note that not
640-
/// all Windows APIs use `INVALID_HANDLE_VALUE` for errors; see [here] for
641-
/// the full story.
626+
/// The passed `handle` value must either satisfy the safety requirements
627+
/// of [`FromRawHandle::from_raw_handle`], or be
628+
/// `INVALID_HANDLE_VALUE` (-1). Note that not all Windows APIs use
629+
/// `INVALID_HANDLE_VALUE` for errors; see [here] for the full story.
642630
///
643631
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
644632
#[inline]
645-
unsafe fn from_raw_handle(handle: RawHandle) -> Self {
633+
pub unsafe fn from_raw_handle(handle: RawHandle) -> Self {
646634
Self(handle)
647635
}
648636
}
649637

650638
#[cfg(windows)]
651-
impl FromRawHandle for HandleOrNull {
639+
impl HandleOrNull {
652640
/// Constructs a new instance of `Self` from the given `RawHandle` returned
653641
/// from a Windows API that uses null to indicate failure, such as
654642
/// `CreateThread`.
@@ -658,13 +646,13 @@ impl FromRawHandle for HandleOrNull {
658646
///
659647
/// # Safety
660648
///
661-
/// The resource pointed to by `handle` must be either open and otherwise
662-
/// unowned, or null. Note that not all Windows APIs use null for errors;
663-
/// see [here] for the full story.
649+
/// The passed `handle` value must either satisfy the safety requirements
650+
/// of [`FromRawHandle::from_raw_handle`], or be null. Note that not all
651+
/// Windows APIs use null for errors; see [here] for the full story.
664652
///
665653
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
666654
#[inline]
667-
unsafe fn from_raw_handle(handle: RawHandle) -> Self {
655+
pub unsafe fn from_raw_handle(handle: RawHandle) -> Self {
668656
Self(handle)
669657
}
670658
}

0 commit comments

Comments
 (0)