#[repr(transparent)]pub struct HandleOrNull(_);
Expand description
FFI type for handles in return values or out parameters, where NULL
is used
as a sentry value to indicate errors, such as in the return value of CreateThread
. 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 HandleOrNull
is to convert it into an
OwnedHandle
using its TryFrom
implementation; this conversion takes care of the check for
NULL
. This ensures that such FFI calls cannot start using the handle without
checking for NULL
first.
This type concerns any value other than NULL
to be valid, including INVALID_HANDLE_VALUE
.
This is because APIs that use NULL
as their sentry value don’t treat INVALID_HANDLE_VALUE
as special.
If this holds a valid handle, it will close the handle on drop.
Trait Implementations
sourceimpl Debug for HandleOrNull
impl Debug for HandleOrNull
sourceimpl FromRawHandle for HandleOrNull
impl FromRawHandle for HandleOrNull
sourceunsafe fn from_raw_handle(handle: RawHandle) -> Self
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 null to indicate failure, such as
CreateThread
.
Use HandleOrInvalid
instead of HandleOrNull
for APIs that
use INVALID_HANDLE_VALUE
to indicate failure.
Safety
The resource pointed to by handle
must be either open and otherwise
unowned, or null. Note that not all Windows APIs use null for errors;
see here for the full story.
sourceimpl TryFrom<HandleOrNull> for OwnedHandle
impl TryFrom<HandleOrNull> for OwnedHandle
impl Send for HandleOrNull
impl Sync for HandleOrNull
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more