diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-18 08:08:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-18 08:08:58 +0200 |
| commit | 3aafbd28e54e7da0ba53d84c4dbf37fc027775a2 (patch) | |
| tree | a7f1e5cf86d7142213effc824f45a95753d30830 | |
| parent | 4bb2f278617e5498ac9a4776d3e1268154c500c5 (diff) | |
| parent | 2162f3f34b2b4f9a7d603ab05bec4246a7b855c0 (diff) | |
| download | rust-3aafbd28e54e7da0ba53d84c4dbf37fc027775a2.tar.gz rust-3aafbd28e54e7da0ba53d84c4dbf37fc027775a2.zip | |
Rollup merge of #127077 - tbu-:pr_doc_fd_to_owned, r=workingjubilee
Make language around `ToOwned` for `BorrowedFd` more precise
| -rw-r--r-- | library/std/src/os/fd/owned.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index a1f83029d27..5833c597256 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -24,9 +24,14 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; /// passed as an argument, it is not captured or consumed, and it never has the /// value `-1`. /// -/// This type's `.to_owned()` implementation returns another `BorrowedFd` -/// rather than an `OwnedFd`. It just makes a trivial copy of the raw file -/// descriptor, which is then borrowed under the same lifetime. +/// This type does not have a [`ToOwned`][crate::borrow::ToOwned] +/// implementation. Calling `.to_owned()` on a variable of this type will call +/// it on `&BorrowedFd` and use `Clone::clone()` like `ToOwned` does for all +/// types implementing `Clone`. The result will be descriptor borrowed under +/// the same lifetime. +/// +/// To obtain an [`OwnedFd`], you can use [`BorrowedFd::try_clone_to_owned`] +/// instead, but this is not supported on all platforms. #[derive(Copy, Clone)] #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(0)] @@ -50,6 +55,8 @@ pub struct BorrowedFd<'fd> { /// descriptor, so it can be used in FFI in places where a file descriptor is /// passed as a consumed argument or returned as an owned value, and it never /// has the value `-1`. +/// +/// You can use [`AsFd::as_fd`] to obtain a [`BorrowedFd`]. #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(0)] // libstd/os/raw/mod.rs assures me that every libstd-supported platform has a |
