Confusing `Fd` design in std

Why is there BorrowedFd and OwnedFd when we could have Fd and &Fd?

An &Fd has to actually be a pointer to a variable of type Fd elsewhere, whereas a BorrowedFd has no such requirement. Defining such a variable may be inconvenient in some use-cases. The lifetime restrictions of BorrowedFd exist entirely in the type system.

You can read the motivation in this RFC.

&Fd would add a layer of indirection and not be FFI compatible with RawFd.

3 Likes