From a63e42fe8017cdd2e597a60e4aea5e1f8f25b2d1 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 5 Jul 2021 13:41:21 -0700 Subject: [PATCH] Add a table describing `OwnedFd`, `BorrowedFd`, and `RawFd` by analogy. --- text/0000-io-safety.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/text/0000-io-safety.md b/text/0000-io-safety.md index 3d7d0c8b9c6..d208d353cf2 100644 --- a/text/0000-io-safety.md +++ b/text/0000-io-safety.md @@ -142,6 +142,21 @@ their I/O safety invariants automatically. For Windows, similar types, but in `Handle` and `Socket` forms. +These types play a role for I/O which is analogous to what existing types +in Rust play for memory: + +| Type | Analogous to | +| ---------------- | ------------ | +| `OwnedFd` | `Box<_>` | +| `BorrowedFd<'a>` | `&'a _` | +| `RawFd` | `*const _` | + +One difference is that I/O types don't make a distinction between mutable +and immutable. OS resources can be shared in a variety of ways outside of +Rust's control, so I/O can be thought of as using [interior mutability]. + +[interior mutability]: https://doc.rust-lang.org/reference/interior-mutability.html + ## `AsFd`, `IntoFd`, and `FromFd` These three traits are conceptual replacements for `AsRawFd`, `IntoRawFd`, and