Struct HandleOrInvalid
#[repr(transparent)]
pub struct HandleOrInvalid(pub(in ::os::windows::io::handle) RawHandle);
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.
Fields
0: RawHandle
Implementations
impl HandleOrInvalid
unsafe fn from_raw_handle(handle: RawHandle) -> SelfConstructs a new instance of
Selffrom the givenRawHandlereturned from a Windows API that usesINVALID_HANDLE_VALUEto indicate failure, such asCreateFileW.Use
HandleOrNullinstead ofHandleOrInvalidfor APIs that use null to indicate failure.Safety
The passed
handlevalue must either satisfy the safety requirements ofFromRawHandle::from_raw_handle, or beINVALID_HANDLE_VALUE(-1). Note that not all Windows APIs useINVALID_HANDLE_VALUEfor errors; see here for the full story.fn is_valid(&self) -> bool
Trait Implementations
impl Debug for HandleOrInvalid
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Drop for HandleOrInvalid
fn drop(&mut self)
impl Send for HandleOrInvalid
impl Sync for HandleOrInvalid
Auto Trait Implementations
impl Freeze for HandleOrInvalid
impl RefUnwindSafe for HandleOrInvalid
impl Unpin for HandleOrInvalid
impl UnsafeUnpin for HandleOrInvalid
impl UnwindSafe for HandleOrInvalid
Blanket Implementations
impl<T> Any for HandleOrInvalid
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for HandleOrInvalid
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for HandleOrInvalid
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for HandleOrInvalid
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for HandleOrInvalid
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for HandleOrInvalid
impl<T, U> Into<U> for HandleOrInvalid
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for HandleOrInvalid
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 HandleOrInvalid
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>