# Struct std::os::windows::io::HandleOrInvalid
[−][src]

    #[repr(transparent)]pub struct HandleOrInvalid(_);

🔬 This is a nightly-only experimental API. (`io_safety` #87074)
This is supported on Windows only.
Expand description

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.

If this holds a valid handle, it will close the handle on drop.

## Trait Implementations

[src]

### impl Debug for HandleOrInvalid

[src]

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

Formats the value using the given formatter. Read more

[src]

### impl FromRawHandle for HandleOrInvalid

[src]

#### 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 `INVALID_HANDLE_VALUE` to indicate failure, such as `CreateFileW`.

Use `Option<OwnedHandle>` instead of `HandleOrInvalid` for APIs that use null to indicate failure.

##### Safety

The resource pointed to by `handle` must be either open and otherwise unowned, or equal to `INVALID_HANDLE_VALUE` (-1). It must not be null. Note that not all Windows APIs use `INVALID_HANDLE_VALUE` for errors; see here for the full story.

[src]

### impl TryFrom<HandleOrInvalid> for OwnedHandle

#### type Error = ()

The type returned in the event of a conversion error.

[src]

#### fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, ()>

Performs the conversion.

[src]

### impl Send for HandleOrInvalid

[src]

### impl Sync for HandleOrInvalid

## Auto Trait Implementations

### impl RefUnwindSafe for HandleOrInvalid

### impl Unpin for HandleOrInvalid

### impl UnwindSafe for HandleOrInvalid

## Blanket Implementations

[src]

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

[src]

#### pub fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more

[src]

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

[src]

#### pub fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

[src]

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

[src]

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

Mutably borrows from an owned value. Read more

[src]

### impl<T> From<T> for T

[src]

#### pub fn from(t: T) -> T

Performs the conversion.

[src]

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

[src]

#### pub fn into(self) -> U

Performs the conversion.

[src]

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

#### type Error = Infallible

The type returned in the event of a conversion error.

[src]

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

Performs the conversion.

[src]

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

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

The type returned in the event of a conversion error.

[src]

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

Performs the conversion.