Skip to content

Commit 1290cd4

Browse files
committed
further expand on Arc and Box analogy
1 parent 6d65379 commit 1290cd4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: library/std/src/io/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,12 @@
272272
//! same kernel object. However, when you create a new kernel object, you know that you are holding
273273
//! the only reference to it. Just be careful not to lend it to anyone, since they can obtain a
274274
//! clone and then you can no longer know what the reference count is! In that sense, [`OwnedFd`] is
275-
//! like `Arc` and [`BorrowedFd<'a>`] is like `&'a Arc` (and similar for the Windows types). There
276-
//! is no equivalent to `Box` for file descriptors in the standard library (that would be a type
277-
//! that guarantees that the reference count is `1`).
275+
//! like `Arc` and [`BorrowedFd<'a>`] is like `&'a Arc` (and similar for the Windows types). In
276+
//! particular, given a `BorrowedFd<'a>`, you are not allowed to close the file descriptor -- just
277+
//! like how, given a `&'a Arc`, you are not allowed to decrement the reference count and
278+
//! potentially free the underlying object. There is no equivalent to `Box` for file descriptors in
279+
//! the standard library (that would be a type that guarantees that the reference count is `1`),
280+
//! however, it would be possible for a crate to define a type with those semantics.
278281
//!
279282
//! [`File`]: crate::fs::File
280283
//! [`TcpStream`]: crate::net::TcpStream

0 commit comments

Comments
 (0)