I'm trying to figure out whether a type should implement FromRawFd
and IntoRawFd
as well as, or instead of, From<OwnedFd> for MyType
and From<MyType> for OwnedFd
.
The type wraps an OwnedFd
and endows it with a bunch of methods (that make ioctl
calls on the device that we presume the file descriptor refers to, but that's not important right now -- what matters is that this type stands in basically the same relation to OwnedFd
that File
does, but its purpose is different).
All the trait documentation says on the subject is
This [trait] is typically used to consume ownership of the specified file descriptor. When used in this way, the returned object will take responsibility for closing it when the object goes out of scope.
However, consuming ownership is not strictly required. Use a
From<OwnedFd>::from
implementation for an API which strictly consumes ownership.
In my case, the API definitely is intended to transfer ownership (for both conversions) and so it seems like maybe I ought to implement only From<OwnedFd>
? But it's not saying anything concrete or definite enough for me to be sure.