pub trait Handle: Sized + PartialEq + Eq + Send + Hash + Debug + Display + LowerHex + UpperHex {
const NULL: Self;
const INVALID: Self;
// Required methods
unsafe fn from_ptr(p: *mut c_void) -> Self;
unsafe fn as_mut(&mut self) -> &mut *mut c_void;
fn ptr(&self) -> *mut c_void;
// Provided methods
unsafe fn raw_copy(&self) -> Self { ... }
fn as_opt(&self) -> Option<&Self> { ... }
}
kernel
only.Expand description
A native handle, implemented by all handle types.
Prefer importing this trait through the prelude:
use winsafe::prelude::*;
Required Associated Constants§
sourceconst INVALID: Self
const INVALID: Self
The invalid handle; equals to -1
.
Operations upon this handle will fail with
ERROR::INVALID_HANDLE
error code.
Required Methods§
sourceunsafe fn from_ptr(p: *mut c_void) -> Self
unsafe fn from_ptr(p: *mut c_void) -> Self
Creates a new handle object by wrapping a pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
Be sure the pointer has the correct type and isn’t owned by anyone else, otherwise you may cause memory access violations.
sourceunsafe fn as_mut(&mut self) -> &mut *mut c_void
unsafe fn as_mut(&mut self) -> &mut *mut c_void
Returns a mutable reference to the underlying raw pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
sourcefn ptr(&self) -> *mut c_void
fn ptr(&self) -> *mut c_void
Returns the underlying raw pointer.
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
This method can be used as an escape hatch to interoperate with other libraries.
Provided Methods§
sourceunsafe fn raw_copy(&self) -> Self
unsafe fn raw_copy(&self) -> Self
Returns a raw copy of the underlying handle pointer.
§Safety
As the name implies, raw_copy
returns a raw copy of the handle, so
closing one of the copies won’t close the others. This means a handle
can be used after it has been closed, what can lead to errors and
undefined behavior. Even worse: sometimes Windows reuses handle values,
so you can call a method on a completely different handle type, what can
be catastrophic.
However, in some cases the Windows API demands a copy of the handle –
raw_copy
is an escape hatch to fill this gap.
Object Safety§
Implementors§
source§impl Handle for HIMAGELIST
Available on crate feature comctl
only.
impl Handle for HIMAGELIST
comctl
only.source§impl Handle for HVERSIONINFO
Available on crate feature version
only.
impl Handle for HVERSIONINFO
version
only.