@@ -157,16 +157,17 @@ Rust's control, so I/O can be thought of as using [interior mutability].
157157
158158[ interior mutability ] : https://doc.rust-lang.org/reference/interior-mutability.html
159159
160- ## ` AsFd ` , ` IntoFd ` , and ` FromFd `
160+ ## ` AsFd ` , ` Into<OwnedFd> ` , and ` From<OwnedFd> `
161161
162- These three traits are conceptual replacements for ` AsRawFd ` , ` IntoRawFd ` , and
163- ` FromRawFd ` for most use cases. They work in terms of ` OwnedFd ` and
164- ` BorrowedFd ` , so they automatically enforce their I/O safety invariants.
162+ These three are conceptual replacements for ` AsRawFd::as_raw_fd ` ,
163+ ` IntoRawFd::into_raw_fd ` , and ` FromRawFd::from_raw_fd ` , respectively,
164+ for most use cases. They work in terms of ` OwnedFd ` and ` BorrowedFd ` , so
165+ they automatically enforce their I/O safety invariants.
165166
166- Using these traits , the ` do_some_io ` example in the [ motivation] can avoid
167- the original problems. Since ` AsFd ` is only implemented for types which
168- properly own or borrow their file descriptors, this version of ` do_some_io `
169- doesn't have to worry about being passed bogus or dangling file descriptors:
167+ Using these, the ` do_some_io ` example in the [ motivation] can avoid the
168+ original problems. Since ` AsFd ` is only implemented for types which properly
169+ own or borrow their file descriptors, this version of ` do_some_io ` doesn't
170+ have to worry about being passed bogus or dangling file descriptors:
170171
171172``` rust
172173pub fn do_some_io <FD : AsFd >(input : & FD ) -> io :: Result <()> {
@@ -226,10 +227,11 @@ These types also implement the existing `AsRawFd`, `IntoRawFd`, and `FromRawFd`
226227traits, so they can interoperate with existing code that works with ` RawFd `
227228types.
228229
229- ## ` AsFd ` , ` IntoFd ` , and ` FromFd `
230+ ## ` AsFd ` , ` Into<OwnedFd> ` , and ` From<OwnedFd> `
230231
231- These types provide ` as_fd ` , ` into_fd ` , and ` from_fd ` functions similar to
232- their ` Raw ` counterparts.
232+ These types provide ` as_fd ` , ` into ` , and ` from ` functions similar to
233+ ` AsRawFd::as_raw_fd ` , ` IntoRawFd::into_raw_fd ` , and ` FromRawFd::from_raw_fd ` ,
234+ respectively.
233235
234236## Prototype implementation
235237
@@ -249,7 +251,7 @@ unsafe.
249251
250252Crates using ` AsRawFd ` or ` IntoRawFd ` to accept "any file-like type" or "any
251253socket-like type", such as [ ` socket2 ` ] 's [ ` SockRef::from ` ] , would need to
252- either switch to ` AsFd ` or ` IntoFd ` , or make these functions unsafe.
254+ either switch to ` AsFd ` or ` Into<OwnedFd> ` , or make these functions unsafe.
253255
254256# Rationale and alternatives
255257[ rationale-and-alternatives ] : #rationale-and-alternatives
@@ -385,11 +387,11 @@ Some possible future ideas that could build on this RFC include:
385387 that, with this new guarantee, the high-level wrappers around raw handles
386388 are unforgeable in safe Rust.
387389
388- - There are a few convenience features which can be implemented on top
389- of the basic ` As ` / ` Into ` / ` From ` traits :
390- - A ` from_into_fd ` function which takes a ` IntoFd ` and converts it into a
391- ` FromFd ` , allowing users to perform this common sequence in a single
392- step.
390+ - There are a few convenience features which can be implemented for types
391+ that implement ` AsFd ` , ` Into<OwnedFd> ` , and/or ` From<OwnedFd> ` :
392+ - A ` from_into_fd ` function which takes a ` Into<OwnedFd> ` and converts it
393+ into a ` From<OwnedFd> ` , allowing users to perform this common sequence
394+ in a single step.
393395 - A ` as_filelike_view::<T>() ` function returns a ` View ` , which contains a
394396 temporary instance of T constructed from the contained file descriptor,
395397 allowing users to "view" a raw file descriptor as a ` File ` , ` TcpStream ` ,
@@ -402,7 +404,8 @@ Some possible future ideas that could build on this RFC include:
402404 ` Filelike ` and ` Socketlike ` abstractions could allow code which works in
403405 this way to be generic over Unix and Windows.
404406
405- Similar portability abstractions could apply to the ` From* ` and ` Into* ` traits.
407+ Similar portability abstractions could apply to ` From<OwnedFd> ` and
408+ ` Into<OwnedFd> ` .
406409
407410# Thanks
408411[ thanks ] : #thanks
0 commit comments