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]
unsafe fn from_unowned_raw(i: RawFd) -> Result<OwnedFd>
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)
fn dup(&self) -> Result<OwnedFd>
Duplicate this OwnedFd, and allow the error to be detected.
Clone uses this, but panics on error
fn from<T: IntoRawFd>(i: T) -> Self
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
Methods from Deref<Target = FdRef>
Trait Implementations
impl AsRawFd for OwnedFd
[src]
impl IntoRawFd for OwnedFd
[src]
fn into_raw_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor. Read more
impl FromRawFd for OwnedFd
[src]
unsafe fn from_raw_fd(fd: RawFd) -> OwnedFd
Constructs a new instance of Self
from the given raw file descriptor. Read more
impl Drop for OwnedFd
[src]
impl Clone for OwnedFd
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more