Skip to main content

HandleRef

Struct HandleRef 

Source
pub struct HandleRef<'fd> { /* private fields */ }
Expand description

Borrowed version of Handle.

Unlike Handle, when HandleRef is dropped the underlying file descriptor is not closed. This is mainly useful for programs and libraries that have to do operations on &Files and BorrowedFds passed from elsewhere.

Implementations§

Source§

impl HandleRef<'_>

Source

pub fn from_fd(inner: BorrowedFd<'_>) -> HandleRef<'_>

Wrap a BorrowedFd into a HandleRef.

Source

pub fn try_clone(&self) -> Result<Handle, Error>

Create a copy of a HandleRef.

Note that (unlike BorrowedFd::clone) this method creates a full copy of the underlying file descriptor and thus is more equivalent to BorrowedFd::try_clone_to_owned.

To create a shallow copy of a HandleRef, you can use Clone::clone (or just Copy).

Source

pub fn reopen(&self, flags: impl Into<OpenFlags>) -> Result<File, Error>

“Upgrade” the handle to a usable File handle.

This new File handle is suitable for reading and writing. This does not consume the original handle (allowing for it to be used many times).

The File handle will be opened with O_NOCTTY and O_CLOEXEC set, regardless of whether those flags are present in the flags argument. You can correct these yourself if these defaults are not ideal for you:

  1. fcntl(fd, F_SETFD, 0) will let you unset O_CLOEXEC.
  2. ioctl(fd, TIOCSCTTY, 0) will set the fd as the controlling terminal (if you don’t have one already, and the fd references a TTY).

Trait Implementations§

Source§

impl AsFd for HandleRef<'_>

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Access the underlying file descriptor for a HandleRef.

Note: This method is primarily intended to allow for tests and other code to check the status of the underlying file descriptor. It is not safe to use this BorrowedFd directly to do filesystem operations. Please use the provided HandleRef methods.

Source§

impl<'fd> Clone for HandleRef<'fd>

Source§

fn clone(&self) -> HandleRef<'fd>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'fd> Debug for HandleRef<'fd>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'fd> From<BorrowedFd<'fd>> for HandleRef<'fd>

Source§

fn from(fd: BorrowedFd<'fd>) -> Self

Shorthand for HandleRef::from_fd.

Source§

impl<'fd> Copy for HandleRef<'fd>

Auto Trait Implementations§

§

impl<'fd> Freeze for HandleRef<'fd>

§

impl<'fd> RefUnwindSafe for HandleRef<'fd>

§

impl<'fd> Send for HandleRef<'fd>

§

impl<'fd> Sync for HandleRef<'fd>

§

impl<'fd> Unpin for HandleRef<'fd>

§

impl<'fd> UnwindSafe for HandleRef<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.