pub struct SafeDescriptor {
    pub(crate) descriptor: RawFd,
}
Expand description

Wraps a RawDescriptor and safely closes it when self falls out of scope.

Fields§

§descriptor: RawFd

Implementations§

source§

impl SafeDescriptor

source

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

Clones this descriptor, internally creating a new descriptor. The new SafeDescriptor will share the same underlying count within the kernel.

Trait Implementations§

source§

impl AsFd for SafeDescriptor

source§

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

Borrows the file descriptor. Read more
source§

impl AsRawDescriptor for SafeDescriptor

source§

fn as_raw_descriptor(&self) -> RawFd

Returns the underlying raw descriptor. Read more
source§

impl AsRawFd for SafeDescriptor

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl Drop for SafeDescriptor

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<File> for SafeDescriptor

source§

fn from(f: File) -> SafeDescriptor

Converts to this type from the input type.
source§

impl From<SafeDescriptor> for File

source§

fn from(s: SafeDescriptor) -> File

Converts to this type from the input type.
source§

impl From<SharedMemory> for SafeDescriptor

source§

fn from(sm: SharedMemory) -> SafeDescriptor

Converts to this type from the input type.
source§

impl FromRawDescriptor for SafeDescriptor

source§

unsafe fn from_raw_descriptor(descriptor: RawFd) -> Self

Safety

Safe only if the caller ensures nothing has access to the descriptor after passing it to from_raw_descriptor

source§

impl IntoRawDescriptor for SafeDescriptor

source§

impl TryFrom<&dyn AsRawDescriptor> for SafeDescriptor

source§

fn try_from(rd: &dyn AsRawDescriptor) -> Result<Self, Self::Error>

Clones the underlying descriptor (handle), internally creating a new descriptor.

WARNING: Windows does NOT support cloning/duplicating all types of handles. DO NOT use this function on IO completion ports, sockets, or pseudo-handles (except those from GetCurrentProcess or GetCurrentThread). See https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-duplicatehandle for further details.

TODO(b/191800567): this API has sharp edges on Windows. We should evaluate making some adjustments to smooth those edges.

§

type Error = Error

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

impl TryFrom<&dyn AsRawFd> for SafeDescriptor

§

type Error = Error

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

fn try_from(fd: &dyn AsRawFd) -> Result<Self, Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.