diff options
| author | Ralf Jung <post@ralfj.de> | 2023-08-29 21:08:46 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-08-29 21:08:46 +0200 |
| commit | 1290cd432ddc3bf935cbd1d585b5999a38a103bc (patch) | |
| tree | 1c2658073f90378b6c131ef04291b1f93a75aa81 /library/std/src | |
| parent | 6d65379e7a5da8f118803bab5618b6c68994ad37 (diff) | |
| download | rust-1290cd432ddc3bf935cbd1d585b5999a38a103bc.tar.gz rust-1290cd432ddc3bf935cbd1d585b5999a38a103bc.zip | |
further expand on Arc and Box analogy
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/io/mod.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 35f5855d7f9..b3cb21125c7 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -272,9 +272,12 @@ //! same kernel object. However, when you create a new kernel object, you know that you are holding //! the only reference to it. Just be careful not to lend it to anyone, since they can obtain a //! clone and then you can no longer know what the reference count is! In that sense, [`OwnedFd`] is -//! like `Arc` and [`BorrowedFd<'a>`] is like `&'a Arc` (and similar for the Windows types). There -//! is no equivalent to `Box` for file descriptors in the standard library (that would be a type -//! that guarantees that the reference count is `1`). +//! like `Arc` and [`BorrowedFd<'a>`] is like `&'a Arc` (and similar for the Windows types). In +//! particular, given a `BorrowedFd<'a>`, you are not allowed to close the file descriptor -- just +//! like how, given a `&'a Arc`, you are not allowed to decrement the reference count and +//! potentially free the underlying object. There is no equivalent to `Box` for file descriptors in +//! the standard library (that would be a type that guarantees that the reference count is `1`), +//! however, it would be possible for a crate to define a type with those semantics. //! //! [`File`]: crate::fs::File //! [`TcpStream`]: crate::net::TcpStream |
