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<'_>
impl HandleRef<'_>
Sourcepub fn from_fd(inner: BorrowedFd<'_>) -> HandleRef<'_>
pub fn from_fd(inner: BorrowedFd<'_>) -> HandleRef<'_>
Wrap a BorrowedFd into a HandleRef.
Sourcepub fn try_clone(&self) -> Result<Handle, Error>
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).
Sourcepub fn reopen(&self, flags: impl Into<OpenFlags>) -> Result<File, Error>
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:
fcntl(fd, F_SETFD, 0)will let you unsetO_CLOEXEC.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<'_>
impl AsFd for HandleRef<'_>
Source§fn as_fd(&self) -> BorrowedFd<'_>
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> From<BorrowedFd<'fd>> for HandleRef<'fd>
impl<'fd> From<BorrowedFd<'fd>> for HandleRef<'fd>
Source§fn from(fd: BorrowedFd<'fd>) -> Self
fn from(fd: BorrowedFd<'fd>) -> Self
Shorthand for HandleRef::from_fd.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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