std::os::windows::io

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

Implementations§

Source§

impl HandleOrNull

1.63.0 · Source

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

Trait Implementations§

1.63.0 · Source§

impl Debug for HandleOrNull

Source§

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

Formats the value using the given formatter. Read more
1.63.0 · Source§

impl Drop for HandleOrNull

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
1.63.0 · Source§

impl TryFrom<HandleOrNull> for OwnedHandle

Source§

type Error = NullHandleError

The type returned in the event of a conversion error.
Source§

fn try_from(handle_or_null: HandleOrNull) -> Result<Self, NullHandleError>

Performs the conversion.
1.63.0 · Source§

impl Send for HandleOrNull

1.63.0 · Source§

impl Sync for HandleOrNull

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.