Struct windows_helpers::ResGuard
source · pub struct ResGuard<R, S, F>{ /* 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, S, F> ResGuard<R, S, F>
impl<R, S, F> ResGuard<R, S, F>
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.
sourcepub fn with_mut_acquisition<A, T, E>(acquire: A, free: F) -> Result<Self, E>
pub fn with_mut_acquisition<A, T, E>(acquire: A, free: F) -> Result<Self, E>
For functions that provide the resource by means of an out-parameter.
sourcepub fn two_with_mut_acquisition<A, T, E>(
acquire_both: A,
free_first: F,
free_second: F
) -> Result<(Self, Self), E>
pub fn two_with_mut_acquisition<A, T, E>( acquire_both: A, free_first: F, free_second: F ) -> Result<(Self, Self), E>
For purpose, see Self::two_with_mut_acq_and_close_handle().
source§impl<R> ResGuard<R, HANDLE, fn(_: R)>where
R: CanInto<HANDLE> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HANDLE, fn(_: R)>where
R: CanInto<HANDLE> + TypeKind<TypeKind = CopyType> + Clone,
sourcepub fn with_acq_and_close_handle<A, E>(
acquire: A
) -> Result<ResGuard<R, HANDLE, fn(_: R)>, E>
pub fn with_acq_and_close_handle<A, E>( acquire: A ) -> Result<ResGuard<R, HANDLE, fn(_: R)>, E>
Activate feature HANDLE_CloseHandle.
source§impl<R> ResGuard<R, HDC, fn(_: R)>where
R: CanInto<HDC> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HDC, fn(_: R)>where
R: CanInto<HDC> + TypeKind<TypeKind = CopyType> + Clone,
sourcepub fn with_acq_and_delete_dc<A, E>(
acquire: A
) -> Result<ResGuard<R, HDC, fn(_: R)>, E>
pub fn with_acq_and_delete_dc<A, E>( acquire: A ) -> Result<ResGuard<R, HDC, fn(_: R)>, E>
Activate feature HDC_DeleteDC.
source§impl<R> ResGuard<R, HGDIOBJ, fn(_: R)>where
R: CanInto<HGDIOBJ> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HGDIOBJ, fn(_: R)>where
R: CanInto<HGDIOBJ> + TypeKind<TypeKind = CopyType> + Clone,
sourcepub fn with_acq_and_delete_object<A, E>(
acquire: A
) -> Result<ResGuard<R, HGDIOBJ, fn(_: R)>, E>
pub fn with_acq_and_delete_object<A, E>( acquire: A ) -> Result<ResGuard<R, HGDIOBJ, fn(_: R)>, E>
Activate feature HGDIOBJ_DeleteObject.
source§impl<R> ResGuard<R, HGLOBAL, fn(_: R)>where
R: CanInto<HGLOBAL> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HGLOBAL, fn(_: R)>where
R: CanInto<HGLOBAL> + TypeKind<TypeKind = CopyType> + Clone,
sourcepub fn with_acq_and_global_free<A, E>(
acquire: A
) -> Result<ResGuard<R, HGLOBAL, fn(_: R)>, E>
pub fn with_acq_and_global_free<A, E>( acquire: A ) -> Result<ResGuard<R, HGLOBAL, fn(_: R)>, E>
Activate feature HGLOBAL_GlobalFree.
source§impl<R> ResGuard<R, HICON, fn(_: R)>where
R: CanInto<HICON> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HICON, fn(_: R)>where
R: CanInto<HICON> + TypeKind<TypeKind = CopyType> + Clone,
sourcepub fn with_acq_and_destroy_icon<A, E>(
acquire: A
) -> Result<ResGuard<R, HICON, fn(_: R)>, E>
pub fn with_acq_and_destroy_icon<A, E>( acquire: A ) -> Result<ResGuard<R, HICON, fn(_: R)>, E>
Activate feature HICON_DestroyIcon.
source§impl<R> ResGuard<R, HLOCAL, fn(_: R)>where
R: CanInto<HLOCAL> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HLOCAL, fn(_: R)>where
R: CanInto<HLOCAL> + TypeKind<TypeKind = CopyType> + Clone,
sourcepub fn with_acq_and_local_free<A, E>(
acquire: A
) -> Result<ResGuard<R, HLOCAL, fn(_: R)>, E>
pub fn with_acq_and_local_free<A, E>( acquire: A ) -> Result<ResGuard<R, HLOCAL, fn(_: R)>, E>
Activate feature HLOCAL_LocalFree.
source§impl<R> ResGuard<R, HMENU, fn(_: R)>where
R: CanInto<HMENU> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HMENU, fn(_: R)>where
R: CanInto<HMENU> + TypeKind<TypeKind = CopyType> + Clone,
Activate feature HMENU_DestroyMenu.
Activate feature HMENU_DestroyMenu.
source§impl<R> ResGuard<R, HMODULE, fn(_: R)>where
R: CanInto<HMODULE> + TypeKind<TypeKind = CopyType> + Clone,
impl<R> ResGuard<R, HMODULE, fn(_: R)>where
R: CanInto<HMODULE> + TypeKind<TypeKind = CopyType> + Clone,
sourcepub fn with_acq_and_free_library<A, E>(
acquire: A
) -> Result<ResGuard<R, HMODULE, fn(_: R)>, E>
pub fn with_acq_and_free_library<A, E>( acquire: A ) -> Result<ResGuard<R, HMODULE, fn(_: R)>, E>
Activate feature HMODULE_FreeLibrary.