HandleOrNull in std::os::windows::io - Rust (original) (raw)
Struct HandleOrNull
1.63.0 · Source
pub struct HandleOrNull(/* private fields */);
Available on Windows only.
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 usesrepr(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 anOwnedHandle
using its TryFrom implementation; this conversion takes care of the check forNULL
. This ensures that such FFI calls cannot start using the handle without checking for NULL
first.
This type may hold any handle value that OwnedHandle may hold. As with OwnedHandle
, when it holds -1
, that value is interpreted as a valid handle value, such asthe current process handle, and not INVALID_HANDLE_VALUE
.
If this holds a non-null handle, it will close the handle on drop.
1.63.0 · Source
Constructs a new instance of Self
from the given RawHandle
returned from a Windows API that uses null to indicate failure, such asCreateThread
.
Use HandleOrInvalid
instead of HandleOrNull
for APIs that use INVALID_HANDLE_VALUE
to indicate failure.
§Safety
The passed handle
value must either satisfy the safety requirements of FromRawHandle::from_raw_handle, or be null. Note that not all Windows APIs use null for errors; see here for the full story.