Skip to content

Commit a63e42f

Browse files
committed
Add a table describing OwnedFd, BorrowedFd, and RawFd by analogy.
1 parent 60b6181 commit a63e42f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

text/0000-io-safety.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ their I/O safety invariants automatically.
142142

143143
For Windows, similar types, but in `Handle` and `Socket` forms.
144144

145+
These types play a role for I/O which is analogous to what existing types
146+
in Rust play for memory:
147+
148+
| Type | Analogous to |
149+
| ---------------- | ------------ |
150+
| `OwnedFd` | `Box<_>` |
151+
| `BorrowedFd<'a>` | `&'a _` |
152+
| `RawFd` | `*const _` |
153+
154+
One difference is that I/O types don't make a distinction between mutable
155+
and immutable. OS resources can be shared in a variety of ways outside of
156+
Rust's control, so I/O can be thought of as using [interior mutability].
157+
158+
[interior mutability]: https://doc.rust-lang.org/reference/interior-mutability.html
159+
145160
## `AsFd`, `IntoFd`, and `FromFd`
146161

147162
These three traits are conceptual replacements for `AsRawFd`, `IntoRawFd`, and

0 commit comments

Comments
 (0)