Skip to content

Commit 0000fe0

Browse files
authored
Rollup merge of rust-lang#93354 - sunfishcode:sunfishcode/document-borrowedfd-toowned, r=joshtriplett
Add documentation about `BorrowedFd::to_owned`. Following up on rust-lang#88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? ````@joshtriplett````
2 parents 27288b7 + 47aaf79 commit 0000fe0

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

library/std/src/os/fd/owned.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
2121
/// descriptor, so it can be used in FFI in places where a file descriptor is
2222
/// passed as an argument, it is not captured or consumed, and it never has the
2323
/// value `-1`.
24+
///
25+
/// This type's `.to_owned()` implementation returns another `BorrowedFd`
26+
/// rather than an `OwnedFd`. It just makes a trivial copy of the raw file
27+
/// descriptor, which is then borrowed under the same lifetime.
2428
#[derive(Copy, Clone)]
2529
#[repr(transparent)]
2630
#[rustc_layout_scalar_valid_range_start(0)]

library/std/src/os/windows/io/handle.rs

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
2828
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
2929
/// detached from processes, or when `windows_subsystem` is used.
3030
///
31+
/// This type's `.to_owned()` implementation returns another `BorrowedHandle`
32+
/// rather than an `OwnedHandle`. It just makes a trivial copy of the raw
33+
/// handle, which is then borrowed under the same lifetime.
34+
///
3135
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
3236
#[derive(Copy, Clone)]
3337
#[repr(transparent)]

library/std/src/os/windows/io/socket.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ use crate::sys::cvt;
2121
/// so it can be used in FFI in places where a socket is passed as an argument,
2222
/// it is not captured or consumed, and it never has the value
2323
/// `INVALID_SOCKET`.
24+
///
25+
/// This type's `.to_owned()` implementation returns another `BorrowedSocket`
26+
/// rather than an `OwnedSocket`. It just makes a trivial copy of the raw
27+
/// socket, which is then borrowed under the same lifetime.
2428
#[derive(Copy, Clone)]
2529
#[repr(transparent)]
2630
#[rustc_layout_scalar_valid_range_start(0)]

0 commit comments

Comments
 (0)