Struct OwnedFd

#[repr(transparent)]
pub struct OwnedFd { pub(in ::os::fd::owned) fd: NotAllOnes<RawFd> }

An owned file descriptor.

This closes the file descriptor on drop. It is guaranteed that nobody else will close the file descriptor.

This uses repr(transparent) and has the representation of a host file descriptor, so it can be used in FFI in places where a file descriptor is passed as a consumed argument or returned as an owned value, and it never has the value -1.

You can use AsFd::as_fd to obtain a BorrowedFd.

Fields

fd: NotAllOnes<RawFd>

Implementations

impl OwnedFd

fn try_clone(&self) -> Result<Self>

Creates a new OwnedFd instance that shares the same underlying file description as the existing OwnedFd instance.

Trait Implementations

impl AsFd for OwnedFd

fn as_fd(&self) -> BorrowedFd<'_>

impl AsRawFd for OwnedFd

fn as_raw_fd(&self) -> RawFd

impl Debug for OwnedFd

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Drop for OwnedFd

fn drop(&mut self)

impl From<ChildStderr> for OwnedFd

fn from(child_stderr: ChildStderr) -> OwnedFd

Takes ownership of a ChildStderr's file descriptor.

impl From<ChildStdin> for OwnedFd

fn from(child_stdin: ChildStdin) -> OwnedFd

Takes ownership of a ChildStdin's file descriptor.

impl From<ChildStdout> for OwnedFd

fn from(child_stdout: ChildStdout) -> OwnedFd

Takes ownership of a ChildStdout's file descriptor.

impl From<Dir> for OwnedFd

fn from(value: Dir) -> Self

impl From<File> for OwnedFd

fn from(file: File) -> OwnedFd

Takes ownership of a File's underlying file descriptor.

impl From<PidFd> for OwnedFd

fn from(pid_fd: PidFd) -> Self

impl From<PipeReader> for OwnedFd

fn from(pipe: PipeReader) -> Self

impl From<PipeWriter> for OwnedFd

fn from(pipe: PipeWriter) -> Self

impl From<TcpListener> for OwnedFd

fn from(tcp_listener: TcpListener) -> OwnedFd

Takes ownership of a TcpListener's socket file descriptor.

impl From<TcpStream> for OwnedFd

fn from(tcp_stream: TcpStream) -> OwnedFd

Takes ownership of a TcpStream's socket file descriptor.

impl From<UdpSocket> for OwnedFd

fn from(udp_socket: UdpSocket) -> OwnedFd

Takes ownership of a UdpSocket's file descriptor.

impl From<UnixDatagram> for OwnedFd

fn from(unix_datagram: UnixDatagram) -> OwnedFd

Takes ownership of a UnixDatagram's socket file descriptor.

impl From<UnixListener> for OwnedFd

fn from(listener: UnixListener) -> OwnedFd

Takes ownership of a UnixListener's socket file descriptor.

impl From<UnixStream> for OwnedFd

fn from(unix_stream: UnixStream) -> OwnedFd

Takes ownership of a UnixStream's socket file descriptor.

impl FromRawFd for OwnedFd

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor.

Safety

The resource pointed to by fd must be open and suitable for assuming ownership. The resource must not require any cleanup other than close.

Panics

Panics if the raw file descriptor has the value -1.

impl IntoRawFd for OwnedFd

fn into_raw_fd(self) -> RawFd

impl IsTerminal for OwnedFd

fn is_terminal(&self) -> bool

Auto Trait Implementations

impl Freeze for OwnedFd

impl RefUnwindSafe for OwnedFd

impl Send for OwnedFd

impl Sync for OwnedFd

impl Unpin for OwnedFd

impl UnsafeUnpin for OwnedFd

impl UnwindSafe for OwnedFd

Blanket Implementations

impl<T> Any for OwnedFd where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for OwnedFd where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for OwnedFd where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for OwnedFd

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for OwnedFd where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for OwnedFd

impl<T, U> Into<U> for OwnedFd where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for OwnedFd where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for OwnedFd where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>