#[repr(transparent)]pub struct HandleOrInvalid(RawHandle);Expand description
FFI type for handles in return values or out parameters, where INVALID_HANDLE_VALUE is used
as a sentry value to indicate errors, such as in the return value of CreateFileW. This uses
repr(transparent) and has the representation of a host handle, so that it can be used in such
FFI declarations.
The only thing you can usefully do with a HandleOrInvalid is to convert it into an
OwnedHandle using its TryFrom implementation; this conversion takes care of the check for
INVALID_HANDLE_VALUE. This ensures that such FFI calls cannot start using the handle without
checking for INVALID_HANDLE_VALUE first.
This type may hold any handle value that OwnedHandle may hold, except that when it holds
-1, that value is interpreted to mean INVALID_HANDLE_VALUE.
If holds a handle other than INVALID_HANDLE_VALUE, it will close the handle on drop.
Tuple Fields§
§0: RawHandleImplementations§
Source§impl HandleOrInvalid
impl HandleOrInvalid
1.63.0 · Sourcepub unsafe fn from_raw_handle(handle: RawHandle) -> Self
pub unsafe fn from_raw_handle(handle: RawHandle) -> Self
Constructs a new instance of Self from the given RawHandle returned
from a Windows API that uses INVALID_HANDLE_VALUE to indicate
failure, such as CreateFileW.
Use HandleOrNull instead of HandleOrInvalid for APIs that
use null to indicate failure.
§Safety
The passed handle value must either satisfy the safety requirements
of FromRawHandle::from_raw_handle, or be
INVALID_HANDLE_VALUE (-1). Note that not all Windows APIs use
INVALID_HANDLE_VALUE for errors; see here for the full story.
fn is_valid(&self) -> bool
Trait Implementations§
1.63.0 · Source§impl Debug for HandleOrInvalid
impl Debug for HandleOrInvalid
1.63.0 · Source§impl Drop for HandleOrInvalid
impl Drop for HandleOrInvalid
1.63.0 · Source§impl TryFrom<HandleOrInvalid> for OwnedHandle
impl TryFrom<HandleOrInvalid> for OwnedHandle
Source§type Error = InvalidHandleError
type Error = InvalidHandleError
Source§fn try_from(
handle_or_invalid: HandleOrInvalid,
) -> Result<Self, InvalidHandleError>
fn try_from( handle_or_invalid: HandleOrInvalid, ) -> Result<Self, InvalidHandleError>
impl Send for HandleOrInvalid
impl Sync for HandleOrInvalid
Auto Trait Implementations§
impl Freeze for HandleOrInvalid
impl RefUnwindSafe for HandleOrInvalid
impl Unpin for HandleOrInvalid
impl UnwindSafe for HandleOrInvalid
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> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const SIZE: usize = _
#[doc(hidden)] const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)] const ALIGN: usize = _
#[doc(hidden)] const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more