Trait base::descriptor::AsRawDescriptor
source · pub trait AsRawDescriptor {
// Required method
fn as_raw_descriptor(&self) -> RawDescriptor;
}
Expand description
Trait for returning the underlying raw descriptor, without giving up ownership of the descriptor.
Required Methods§
sourcefn as_raw_descriptor(&self) -> RawDescriptor
fn as_raw_descriptor(&self) -> RawDescriptor
Returns the underlying raw descriptor.
Since the descriptor is still owned by the provider, callers should not assume that it will remain open for longer than the immediate call of this method. In particular, it is a dangerous practice to store the result of this method for future use: instead, it should be used to e.g. obtain a raw descriptor that is immediately passed to a system call.
If you need to use the descriptor for a longer time (and particularly if you cannot reliably
track the lifetime of the providing object), you should probably consider using
SafeDescriptor
(possibly along with IntoRawDescriptor
) to get full ownership
over a descriptor pointing to the same resource.
Trait Implementations§
source§impl TryFrom<&dyn AsRawDescriptor> for SafeDescriptor
impl TryFrom<&dyn AsRawDescriptor> for SafeDescriptor
source§fn try_from(rd: &dyn AsRawDescriptor) -> Result<Self, Self::Error>
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.
Implementations on Foreign Types§
source§impl AsRawDescriptor for File
impl AsRawDescriptor for File
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for Stderr
impl AsRawDescriptor for Stderr
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for Stdin
impl AsRawDescriptor for Stdin
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for Stdout
impl AsRawDescriptor for Stdout
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for TcpListener
impl AsRawDescriptor for TcpListener
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for TcpStream
impl AsRawDescriptor for TcpStream
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for UdpSocket
impl AsRawDescriptor for UdpSocket
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for OwnedFd
impl AsRawDescriptor for OwnedFd
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for UnixDatagram
impl AsRawDescriptor for UnixDatagram
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for UnixListener
impl AsRawDescriptor for UnixListener
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl AsRawDescriptor for UnixStream
impl AsRawDescriptor for UnixStream
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl<T> AsRawDescriptor for Arc<T>where
T: AsRawDescriptor,
impl<T> AsRawDescriptor for Arc<T>where
T: AsRawDescriptor,
fn as_raw_descriptor(&self) -> RawDescriptor
Implementors§
impl AsRawDescriptor for &StreamChannel
impl AsRawDescriptor for Event
USE THIS CAUTIOUSLY. On Windows, the returned handle is not a file handle and cannot be used as if it were one. It is a handle to a the associated file mapping object and should only be used for memory-mapping the file view.