#[repr(transparent)]
pub struct BorrowedFd<'fd> { fd: i32, _phantom: PhantomData<&'fd OwnedFd>, }
🔬 This is a nightly-only experimental API. (io_safety)
This is supported on Unix only.
Expand description

A borrowed file descriptor.

This has a lifetime parameter to tie it to the lifetime of something that owns 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 an argument, it is not captured or consumed, and it never has the value -1.

This type’s .to_owned() implementation returns another BorrowedFd rather than an OwnedFd. It just makes a trivial copy of the raw file descriptor, which is then borrowed under the same lifetime.

Fields

fd: i32
🔬 This is a nightly-only experimental API. (io_safety)
_phantom: PhantomData<&'fd OwnedFd>
🔬 This is a nightly-only experimental API. (io_safety)

Implementations

🔬 This is a nightly-only experimental API. (io_safety)

Return a BorrowedFd holding the given raw file descriptor.

Safety

The resource pointed to by fd must remain open for the duration of the returned BorrowedFd, and it must not have the value -1.

Trait Implementations

🔬 This is a nightly-only experimental API. (io_safety)

Borrows the file descriptor. Read more

Extracts the raw file descriptor. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.