Struct BorrowedHandle

#[repr(transparent)]
pub struct BorrowedHandle<'handle> { pub(in ::os::windows::io::handle) handle: RawHandle, pub(in ::os::windows::io::handle) _phantom: PhantomData<&'handle OwnedHandle> }

A borrowed handle.

This has a lifetime parameter to tie it to the lifetime of something that owns the handle.

This uses repr(transparent) and has the representation of a host handle, so it can be used in FFI in places where a handle is passed as an argument, it is not captured or consumed.

Note that it may have the value -1, which in BorrowedHandle always represents a valid handle value, such as the current process handle, and not INVALID_HANDLE_VALUE, despite the two having the same value. See here for the full story.

And, it may have the value NULL (0), which can occur when consoles are detached from processes, or when windows_subsystem is used.

This type's .to_owned() implementation returns another BorrowedHandle rather than an OwnedHandle. It just makes a trivial copy of the raw handle, which is then borrowed under the same lifetime.

Fields

handle: RawHandle
_phantom: PhantomData<&'handle OwnedHandle>

Implementations

impl BorrowedHandle<'_>

const unsafe fn borrow_raw(handle: RawHandle) -> Self

Returns a BorrowedHandle holding the given raw handle.

Safety

The resource pointed to by handle must be a valid open handle, it must remain open for the duration of the returned BorrowedHandle.

Note that it may have the value INVALID_HANDLE_VALUE (-1), which is sometimes a valid handle value. See here for the full story.

And, it may have the value NULL (0), which can occur when consoles are detached from processes, or when windows_subsystem is used.

impl BorrowedHandle<'_>

fn try_clone_to_owned(&self) -> Result<OwnedHandle>

Creates a new OwnedHandle instance that shares the same underlying object as the existing BorrowedHandle instance.

fn duplicate(&self, access: u32, inherit: bool, options: u32) -> Result<OwnedHandle>

Trait Implementations

impl AsHandle for BorrowedHandle<'_>

fn as_handle(&self) -> BorrowedHandle<'_>

impl AsRawHandle for BorrowedHandle<'_>

fn as_raw_handle(&self) -> RawHandle

impl Debug for BorrowedHandle<'_>

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

impl IsTerminal for BorrowedHandle<'_>

fn is_terminal(&self) -> bool

impl Send for BorrowedHandle<'_>

impl Sync for BorrowedHandle<'_>

impl<'handle> Clone for BorrowedHandle<'handle>

fn clone(&self) -> BorrowedHandle<'handle>

impl<'handle> Copy for BorrowedHandle<'handle>

impl<'handle> TrivialClone for BorrowedHandle<'handle>

Auto Trait Implementations

impl<'handle> Freeze for BorrowedHandle<'handle>

impl<'handle> RefUnwindSafe for BorrowedHandle<'handle>

impl<'handle> Unpin for BorrowedHandle<'handle>

impl<'handle> UnsafeUnpin for BorrowedHandle<'handle>

impl<'handle> UnwindSafe for BorrowedHandle<'handle>

Blanket Implementations

impl<T> Any for BorrowedHandle<'handle> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for BorrowedHandle<'handle> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for BorrowedHandle<'handle> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for BorrowedHandle<'handle> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for BorrowedHandle<'handle>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for BorrowedHandle<'handle> where T: Copy + Debug,

impl<T> SizeHint for BorrowedHandle<'handle> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for BorrowedHandle<'handle>

impl<T> ToOwned for BorrowedHandle<'handle> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for BorrowedHandle<'handle> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for BorrowedHandle<'handle> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for BorrowedHandle<'handle> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>