Skip to main content

Fd

Struct Fd 

Source
pub struct Fd(/* private fields */);
Expand description

An owned file descriptor that closes on drop.

Fd is move-only. Constructing one from a raw descriptor transfers close ownership to Fd; do not also close the raw descriptor elsewhere.

Implementations§

Source§

impl Fd

Source

pub unsafe fn from_owned_raw_fd( fd: RawFd, op: &'static str, ) -> Result<Self, CoreError>

Wrap an owned raw file descriptor.

§Safety

The caller must guarantee fd is valid, open, and uniquely owned by the returned Fd. Passing a borrowed fd, or closing fd after this call, can cause double-close or use-after-close bugs.

Source

pub fn eventfd(init: u32) -> Result<Self, CoreError>

Create a non-blocking eventfd.

Source

pub fn timerfd() -> Result<Self, CoreError>

Create a non-blocking timerfd using CLOCK_MONOTONIC.

Source

pub fn dup2(&self, target: RawFd) -> Result<(), CoreError>

Perform a dup2 syscall.

Source

pub fn set_nonblock(&self) -> Result<(), CoreError>

Set the O_NONBLOCK flag on the descriptor.

Source

pub fn set_cloexec(&self) -> Result<(), CoreError>

Set the FD_CLOEXEC flag on the descriptor.

Source

pub fn read_slice(&self, buf: &mut [u8]) -> Result<Option<usize>, CoreError>

Read bytes into a mutable slice.

Returns Ok(None) if the operation would block (EAGAIN).

Source

pub fn seek_set(&self, offset: i64) -> Result<u64, CoreError>

Seek to an absolute file offset.

Source

pub fn write_slice(&self, buf: &[u8]) -> Result<Option<usize>, CoreError>

Write bytes from a slice.

Returns Ok(None) if the operation would block (EAGAIN).

Source

pub fn read_u64(&self) -> Result<Option<u64>, CoreError>

Read a native-endian u64.

Returns Ok(None) if the operation would block (EAGAIN).

Source

pub fn write_u64(&self, value: u64) -> Result<Option<usize>, CoreError>

Write a native-endian u64.

Returns Ok(None) if the operation would block (EAGAIN).

Source

pub fn set_timer_oneshot( &self, delay: Option<Duration>, ) -> Result<(), CoreError>

Arm or disarm a one-shot timerfd.

Passing None disarms the timer. Zero durations are rounded up to one nanosecond so the timer still expires.

Trait Implementations§

Source§

impl AsRawFd for Fd

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Drop for Fd

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Freeze for Fd

§

impl RefUnwindSafe for Fd

§

impl Send for Fd

§

impl Sync for Fd

§

impl Unpin for Fd

§

impl UnsafeUnpin for Fd

§

impl UnwindSafe for Fd

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.