Skip to main content

unsafe_impl_fd_asrefs

Macro unsafe_impl_fd_asrefs 

Source
pub(crate) macro unsafe_impl_fd_asrefs($($t:ty),*$(,)?) {
    ...
}
Available on Hermit or Motor OS or Trusty or Unix or WASI only.
Expand description

Implements AsRef<$t> conversions from BorrowedFd to the specified types.

§Safety

It must be sound to transmute &BorrowedFd to &$t.

This typically implies that:

  • $t must be a wrapper with BorrowedFd, OwnedFd or RawFd being the single non-ZST-field. Nominally it also requires repr(transparent), but std can cheat because we can stay in sync with rustc’s layout implementation details.
  • &$t must not have any methods that would allow closing the file descriptor.
  • &$t impls must tolerate instances being created from any kind of file-descriptor without going through some dedicated constructor function, akin to From<OwnedFd> being a noop conversion.