pub struct Handle { /* private fields */ }Expand description
A handle to an existing inode within a Root.
This handle references an already-resolved path which can be used for the
purpose of “re-opening” the handle and get an actual File which can be
used for ordinary operations.
§Safety
It is critical for the safety of this library that at no point do you
use interfaces like libc::openat directly on the OwnedFd you can
extract from this Handle. You must always do operations through a
valid Root.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn try_clone(&self) -> Result<Self, Error>
pub fn try_clone(&self) -> Result<Self, Error>
Create a copy of an existing Handle.
The new handle is completely independent from the original, but references the same underlying file.
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 Handle
impl AsFd for Handle
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Access the underlying file descriptor for a Handle.
Note: This method is primarily intended to allow for tests and other
code to check the status of the underlying OwnedFd without having to
use OwnedFd::from. It is not safe to use this BorrowedFd
directly to do filesystem operations. Please use the provided
HandleRef methods.
Source§impl From<Handle> for OwnedFd
impl From<Handle> for OwnedFd
Source§fn from(handle: Handle) -> Self
fn from(handle: Handle) -> Self
Unwrap a Handle to reveal the underlying OwnedFd.
Note: This method is primarily intended to allow for file descriptor
passing or otherwise transmitting file descriptor information. If you
want to get a File handle for general use, please use
Handle::reopen instead.
Auto Trait Implementations§
impl Freeze for Handle
impl RefUnwindSafe for Handle
impl Send for Handle
impl Sync for Handle
impl Unpin for Handle
impl UnwindSafe for Handle
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> 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