Struct HandleOrInvalid

struct HandleOrInvalid(_)

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.

Implementations

impl HandleOrInvalid

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.

impl Debug for HandleOrInvalid

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

impl Drop for HandleOrInvalid

fn drop(self: &mut Self)

impl Freeze for HandleOrInvalid

impl RefUnwindSafe for HandleOrInvalid

impl Send for HandleOrInvalid

impl Sync for HandleOrInvalid

impl Unpin for HandleOrInvalid

impl UnsafeUnpin for HandleOrInvalid

impl UnwindSafe for HandleOrInvalid

impl<T> Any for HandleOrInvalid

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for HandleOrInvalid

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for HandleOrInvalid

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

impl<T> From for HandleOrInvalid

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for HandleOrInvalid

fn into(self: 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 for HandleOrInvalid

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

impl<T, U> TryInto for HandleOrInvalid

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