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.
For the convenience functions that spare you of having to provide a free-closure, you have to activate the same features for this crate as the windows crate documentation specifies for the respective handle type and its containing module.
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.