Struct windows_helpers::ResGuard
source · pub struct ResGuard<R, F>where
F: FnOnce(R),{ /* private fields */ }Expand description
Holds a resource and a free-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.
Implementations§
source§impl<R, F> ResGuard<R, F>where
F: FnOnce(R),
impl<R, F> ResGuard<R, F>where
F: FnOnce(R),
sourcepub fn with_acquisition<A, E>(acquire: A, free: F) -> Result<Self, E>
pub fn with_acquisition<A, E>(acquire: A, free: F) -> Result<Self, E>
For functions that return the resource.
source§impl ResGuard<HANDLE, fn(_: HANDLE)>
impl ResGuard<HANDLE, fn(_: HANDLE)>
sourcepub fn with_acq_and_close_handle<A, E>(
acquire: A
) -> Result<ResGuard<HANDLE, fn(_: HANDLE)>, E>
pub fn with_acq_and_close_handle<A, E>( acquire: A ) -> Result<ResGuard<HANDLE, fn(_: HANDLE)>, E>
Activate feature HANDLE_CloseHandle.
source§impl ResGuard<HBITMAP, fn(_: HBITMAP)>
impl ResGuard<HBITMAP, fn(_: HBITMAP)>
sourcepub fn with_acq_and_delete_object<A, E>(
acquire: A
) -> Result<ResGuard<HBITMAP, fn(_: HBITMAP)>, E>
pub fn with_acq_and_delete_object<A, E>( acquire: A ) -> Result<ResGuard<HBITMAP, fn(_: HBITMAP)>, E>
Activate feature HBITMAP_DeleteObject.
source§impl ResGuard<HBRUSH, fn(_: HBRUSH)>
impl ResGuard<HBRUSH, fn(_: HBRUSH)>
sourcepub fn with_acq_and_delete_object<A, E>(
acquire: A
) -> Result<ResGuard<HBRUSH, fn(_: HBRUSH)>, E>
pub fn with_acq_and_delete_object<A, E>( acquire: A ) -> Result<ResGuard<HBRUSH, fn(_: HBRUSH)>, E>
Activate feature HBRUSH_DeleteObject.
source§impl ResGuard<HDC, fn(_: HDC)>
impl ResGuard<HDC, fn(_: HDC)>
sourcepub fn with_acq_and_delete_dc<A, E>(
acquire: A
) -> Result<ResGuard<HDC, fn(_: HDC)>, E>
pub fn with_acq_and_delete_dc<A, E>( acquire: A ) -> Result<ResGuard<HDC, fn(_: HDC)>, E>
Activate feature HDC_DeleteDC.
source§impl ResGuard<HFONT, fn(_: HFONT)>
impl ResGuard<HFONT, fn(_: HFONT)>
sourcepub fn with_acq_and_delete_object<A, E>(
acquire: A
) -> Result<ResGuard<HFONT, fn(_: HFONT)>, E>
pub fn with_acq_and_delete_object<A, E>( acquire: A ) -> Result<ResGuard<HFONT, fn(_: HFONT)>, E>
Activate feature HFONT_DeleteObject.
source§impl ResGuard<HGDIOBJ, fn(_: HGDIOBJ)>
impl ResGuard<HGDIOBJ, fn(_: HGDIOBJ)>
sourcepub fn with_acq_and_delete_object<A, E>(
acquire: A
) -> Result<ResGuard<HGDIOBJ, fn(_: HGDIOBJ)>, E>
pub fn with_acq_and_delete_object<A, E>( acquire: A ) -> Result<ResGuard<HGDIOBJ, fn(_: HGDIOBJ)>, E>
Activate feature HGDIOBJ_DeleteObject.
source§impl ResGuard<HGLOBAL, fn(_: HGLOBAL)>
impl ResGuard<HGLOBAL, fn(_: HGLOBAL)>
sourcepub fn with_acq_and_global_free<A, E>(
acquire: A
) -> Result<ResGuard<HGLOBAL, fn(_: HGLOBAL)>, E>
pub fn with_acq_and_global_free<A, E>( acquire: A ) -> Result<ResGuard<HGLOBAL, fn(_: HGLOBAL)>, E>
Activate feature HGLOBAL_GlobalFree.
source§impl ResGuard<HICON, fn(_: HICON)>
impl ResGuard<HICON, fn(_: HICON)>
sourcepub fn with_acq_and_destroy_icon<A, E>(
acquire: A
) -> Result<ResGuard<HICON, fn(_: HICON)>, E>
pub fn with_acq_and_destroy_icon<A, E>( acquire: A ) -> Result<ResGuard<HICON, fn(_: HICON)>, E>
Activate feature HICON_DestroyIcon.
source§impl ResGuard<HLOCAL, fn(_: HLOCAL)>
impl ResGuard<HLOCAL, fn(_: HLOCAL)>
sourcepub fn with_acq_and_local_free<A, E>(
acquire: A
) -> Result<ResGuard<HLOCAL, fn(_: HLOCAL)>, E>
pub fn with_acq_and_local_free<A, E>( acquire: A ) -> Result<ResGuard<HLOCAL, fn(_: HLOCAL)>, E>
Activate feature HLOCAL_LocalFree.
source§impl ResGuard<HMODULE, fn(_: HMODULE)>
impl ResGuard<HMODULE, fn(_: HMODULE)>
sourcepub fn with_acq_and_free_library<A, E>(
acquire: A
) -> Result<ResGuard<HMODULE, fn(_: HMODULE)>, E>
pub fn with_acq_and_free_library<A, E>( acquire: A ) -> Result<ResGuard<HMODULE, fn(_: HMODULE)>, E>
Activate feature HMODULE_FreeLibrary.
source§impl ResGuard<HPALETTE, fn(_: HPALETTE)>
impl ResGuard<HPALETTE, fn(_: HPALETTE)>
sourcepub fn with_acq_and_delete_object<A, E>(
acquire: A
) -> Result<ResGuard<HPALETTE, fn(_: HPALETTE)>, E>
pub fn with_acq_and_delete_object<A, E>( acquire: A ) -> Result<ResGuard<HPALETTE, fn(_: HPALETTE)>, E>
Activate feature HPALETTE_DeleteObject.
source§impl ResGuard<HPEN, fn(_: HPEN)>
impl ResGuard<HPEN, fn(_: HPEN)>
sourcepub fn with_acq_and_delete_object<A, E>(
acquire: A
) -> Result<ResGuard<HPEN, fn(_: HPEN)>, E>
pub fn with_acq_and_delete_object<A, E>( acquire: A ) -> Result<ResGuard<HPEN, fn(_: HPEN)>, E>
Activate feature HPEN_DeleteObject.