Struct windows_helpers::ResGuard
source · pub struct ResGuard<R: Copy> { /* private fields */ }
Expand description
Holds a resource and a free-function (like a non-capturing closure) that is called when the guard is dropped.
Allows to couple resource acquisition and freeing, while treating the guard as the contained resource and ensuring freeing will happen. When writing the code, it’s also nice to transfer the documentation into everything that has to happen in one go without having to split it into upper and lower or here- and there-code. In a function, Rust’s drop order should ensure that later aquired resources are freed first.
For functions ending in Windows API function names (differently cased, like ..._destroy_icon()
), you have to activate crate features. First, see the repository’s read-me. Then, derive the needed features from the Windows API function and the handle type the instance manages.
Implementations§
source§impl<R: Copy> ResGuard<R>
impl<R: Copy> ResGuard<R>
sourcepub fn with_acquisition<A, E>(acquire: A, free: fn(_: R)) -> Result<Self, E>
pub fn with_acquisition<A, E>(acquire: A, free: fn(_: R)) -> Result<Self, E>
For use with functions that return the resource.
sourcepub fn with_mut_acquisition<A, T, E>(
acquire: A,
free: fn(_: R),
) -> Result<Self, E>
pub fn with_mut_acquisition<A, T, E>( acquire: A, free: fn(_: R), ) -> Result<Self, E>
For use with functions that provide the resource by means of an out-parameter.
source§impl ResGuard<HANDLE>
impl ResGuard<HANDLE>
pub fn with_res_and_close_handle(resource: HANDLE) -> Self
pub fn with_acq_and_close_handle<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_close_handle<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HBITMAP>
impl ResGuard<HBITMAP>
pub fn with_res_and_delete_object(resource: HBITMAP) -> Self
pub fn with_acq_and_delete_object<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_object<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HBRUSH>
impl ResGuard<HBRUSH>
pub fn with_res_and_delete_object(resource: HBRUSH) -> Self
pub fn with_acq_and_delete_object<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_object<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HDC>
impl ResGuard<HDC>
pub fn with_res_and_delete_dc(resource: HDC) -> Self
pub fn with_acq_and_delete_dc<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_dc<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HFONT>
impl ResGuard<HFONT>
pub fn with_res_and_delete_object(resource: HFONT) -> Self
pub fn with_acq_and_delete_object<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_object<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HGDIOBJ>
impl ResGuard<HGDIOBJ>
pub fn with_res_and_delete_object(resource: HGDIOBJ) -> Self
pub fn with_acq_and_delete_object<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_object<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HGLOBAL>
impl ResGuard<HGLOBAL>
pub fn with_res_and_global_free(resource: HGLOBAL) -> Self
pub fn with_acq_and_global_free<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_global_free<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HICON>
impl ResGuard<HICON>
pub fn with_res_and_destroy_icon(resource: HICON) -> Self
pub fn with_acq_and_destroy_icon<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_destroy_icon<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HLOCAL>
impl ResGuard<HLOCAL>
pub fn with_res_and_local_free(resource: HLOCAL) -> Self
pub fn with_acq_and_local_free<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_local_free<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HMODULE>
impl ResGuard<HMODULE>
pub fn with_res_and_free_library(resource: HMODULE) -> Self
pub fn with_acq_and_free_library<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_free_library<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HPALETTE>
impl ResGuard<HPALETTE>
pub fn with_res_and_delete_object(resource: HPALETTE) -> Self
pub fn with_acq_and_delete_object<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_object<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HPEN>
impl ResGuard<HPEN>
pub fn with_res_and_delete_object(resource: HPEN) -> Self
pub fn with_acq_and_delete_object<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_object<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HPOWERNOTIFY>
impl ResGuard<HPOWERNOTIFY>
pub fn with_res_and_unregister_power_setting_notification( resource: HPOWERNOTIFY, ) -> Self
pub fn with_acq_and_unregister_power_setting_notification<A, E>( acquire: A, ) -> Result<Self, E>
pub fn with_mut_acq_and_unregister_power_setting_notification<A, T, E>( acquire: A, ) -> Result<Self, E>
source§impl ResGuard<HRGN>
impl ResGuard<HRGN>
pub fn with_res_and_delete_object(resource: HRGN) -> Self
pub fn with_acq_and_delete_object<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_delete_object<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<PWSTR>
impl ResGuard<PWSTR>
pub fn with_res_and_local_free(resource: PWSTR) -> Self
pub fn with_acq_and_local_free<A, E>(acquire: A) -> Result<Self, E>
pub fn with_mut_acq_and_local_free<A, T, E>(acquire: A) -> Result<Self, E>
source§impl ResGuard<HANDLE>
impl ResGuard<HANDLE>
sourcepub fn two_with_mut_acq_and_close_handle<A, T, E>(
acquire_both: A,
) -> Result<(Self, Self), E>
pub fn two_with_mut_acq_and_close_handle<A, T, E>( acquire_both: A, ) -> Result<(Self, Self), E>
For a function like CreatePipe()
that returns two resources at once.