Struct owned_fd::OwnedFd [] [src]

pub struct OwnedFd { /* fields omitted */ }

OwnedFd is an RAII wrapper around RawFd: it automatically closes on drop & provides borrow() functionality to support lifetimes & borrow checking around the use of file descriptors

Compared to using File, TcpStream, etc as a wrapper to close on drop, OwnedFd:

  • allows any type of filedescriptor to be used safely
  • has no overhead greater than a RawFd (no buffer, metadata, or other allocations)
  • allows use of the borrow system to ensure drop (close) happens only when all users of an ownedfd have released it.

Methods

impl OwnedFd
[src]

Given a raw file descriptor that may be owned by another (ie: another data structure might close it), create a Owned version that we have control over (via dup())

For taking ownership, see FromRawFd::from_raw_fd().

Unsafety:

  • @i must be a valid file descriptor (of any kind)

Duplicate this OwnedFd, and allow the error to be detected.

Clone uses this, but panics on error

Given a type that impliments IntoRawFd construct an OwnedFd.

This is safe because we assume the promises of IntoRawFd are followed.

NOTE: ideally, we'd impl this as From, but current rust doesn't allow that. Revisit when specialization stabilizes.

Methods from Deref<Target = FdRef>

Trait Implementations

impl AsRawFd for OwnedFd
[src]

Extracts the raw file descriptor. Read more

impl IntoRawFd for OwnedFd
[src]

Consumes this object, returning the raw underlying file descriptor. Read more

impl FromRawFd for OwnedFd
[src]

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

impl Drop for OwnedFd
[src]

A method called when the value goes out of scope. Read more

impl Clone for OwnedFd
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Borrow<FdRef> for OwnedFd
[src]

Immutably borrows from an owned value. Read more

impl Deref for OwnedFd
[src]

The resulting type after dereferencing

The method called to dereference a value