Struct Handle

Source
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

Source

pub fn from_fd_unchecked<Fd: Into<OwnedFd>>(fd: Fd) -> Self

Wrap an OwnedFd into a Handle.

§Safety

The caller guarantees that the provided file is an O_PATH file descriptor with exactly the same semantics as one created through Root::resolve. This means that this function should usually be used to convert an OwnedFd returned from OwnedFd::from (possibly from another process) into a Handle.

While this function is not marked as unsafe (because the safety guarantee required is not related to memory-safety), users should still take great care when using this method because it can cause other kinds of unsafety.

Source

pub fn as_ref(&self) -> HandleRef<'_>

Borrow this Handle as a HandleRef.

Source

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.

Source

pub fn reopen<F: Into<OpenFlags>>(&self, flags: F) -> 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 Handle

Source§

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 Debug for Handle

Source§

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

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

impl From<Handle> for OwnedFd

Source§

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> 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> 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, 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.