[][src]Struct filedesc::FileDesc

pub struct FileDesc { /* fields omitted */ }

Thin wrapper around an open file descriptor.

The wrapped file descriptor will be closed when the wrapper is dropped.

Implementations

impl FileDesc[src]

pub fn new<T: IntoRawFd>(fd: T) -> Self[src]

Create FileDesc from an object that owns a file descriptor.

This does not do anything to the file descriptor other than wrapping it. Notably, it does not set the close-on-exec flag.

pub unsafe fn from_raw_fd(fd: RawFd) -> Self[src]

Wrap a raw file descriptor in a FileDesc.

This does not do anything to the file descriptor other than wrapping it. Notably, it does not set the close-on-exec flag.

Safety

The input must be a valid file descriptor. The file descriptor must not be closed other than by the created FileDesc, unless ownership of the file descriptor is relinquished by calling into_raw_fd().

pub fn duplicate_from<T: AsRawFd>(other: &T) -> Result<Self>[src]

Duplicate a file descriptor from an object that has a file descriptor.

The new file descriptor will have the close-on-exec flag set. If the platform supports it, the flag will be set atomically.

pub unsafe fn duplicate_raw_fd(fd: RawFd) -> Result<Self>[src]

Duplicate a raw file descriptor and wrap it in a FileDesc.

The new file descriptor will have the close-on-exec flag set. If the platform supports it, the flag will be set atomically.

Safety

The input must be a valid file descriptor. The file descriptor must not be closed other than by the created FileDesc, unless ownership of the file descriptor is relinquished by calling into_raw_fd().

pub fn as_raw_fd(&self) -> RawFd[src]

Get the raw file descriptor.

This function does not release ownership of the underlying file descriptor. The file descriptor will still be closed when the FileDesc is dropped.

pub fn into_raw_fd(self) -> RawFd[src]

Release and get the raw file descriptor.

This function releases ownership of the underlying file descriptor. The file descriptor will not be closed.

pub fn duplicate(&self) -> Result<Self>[src]

Try to duplicate the file descriptor.

The new file descriptor will have the close-on-exec flag set. If the platform supports it, the flag will be set atomically.

pub fn set_close_on_exec(&self, close_on_exec: bool) -> Result<()>[src]

Change the close-on-exec flag of the file descriptor.

Note that you should always try to create file descriptors with the close-on-exec flag already set atomically. Setting the flag later on introduces a race condition if another thread forks before the call to set_close_on_exec finishes.

pub fn get_close_on_exec(&self) -> Result<bool>[src]

Check the close-on-exec flag of the file descriptor.

Trait Implementations

impl AsRawFd for FileDesc[src]

impl<'_> AsRawFd for &'_ FileDesc[src]

impl Debug for FileDesc[src]

impl Drop for FileDesc[src]

impl FromRawFd for FileDesc[src]

impl IntoRawFd for FileDesc[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.