Struct HandleOrNull

#[repr(transparent)]
pub struct HandleOrNull(pub(in ::os::windows::io::handle) RawHandle);

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 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 as the current process handle, and not INVALID_HANDLE_VALUE.

If this holds a non-null handle, it will close the handle on drop.

Fields

0: RawHandle

Implementations

impl HandleOrNull

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 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.

fn is_valid(&self) -> bool

Trait Implementations

impl Debug for HandleOrNull

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

impl Drop for HandleOrNull

fn drop(&mut self)

impl Send for HandleOrNull

impl Sync for HandleOrNull

Auto Trait Implementations

impl Freeze for HandleOrNull

impl RefUnwindSafe for HandleOrNull

impl Unpin for HandleOrNull

impl UnsafeUnpin for HandleOrNull

impl UnwindSafe for HandleOrNull

Blanket Implementations

impl<T> Any for HandleOrNull where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for HandleOrNull where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for HandleOrNull where T: ?Sized,

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

impl<T> From<T> for HandleOrNull

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for HandleOrNull where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for HandleOrNull

impl<T, U> Into<U> for HandleOrNull where U: From<T>,

fn into(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<U> for HandleOrNull 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 HandleOrNull where U: TryFrom<T>,

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