pub struct ResourceGuard<T> { /* private fields */ }Expand description
Resource guard that manages the lifetime of a resource
This guard ensures that resources are properly returned to their pool or cleaned up when they’re no longer needed.
Implementations§
Source§impl<T> ResourceGuard<T>
impl<T> ResourceGuard<T>
Sourcepub fn new<F>(resource: T, return_fn: F) -> Self
pub fn new<F>(resource: T, return_fn: F) -> Self
Create a new resource guard
§Arguments
resource: The resource to managereturn_fn: Function to call when returning the resource
Sourcepub fn resource_mut(&mut self) -> &mut T
pub fn resource_mut(&mut self) -> &mut T
Get a mutable reference to the managed resource
Sourcepub fn return_resource(self) -> Result<(), Box<dyn Error + Send + Sync>>
pub fn return_resource(self) -> Result<(), Box<dyn Error + Send + Sync>>
Manually return the resource (consumes the guard)
Sourcepub fn take_ownership(self) -> T
pub fn take_ownership(self) -> T
Take ownership of the resource without returning it to the pool
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ResourceGuard<T>where
T: Freeze,
impl<T> !RefUnwindSafe for ResourceGuard<T>
impl<T> Send for ResourceGuard<T>where
T: Send,
impl<T> !Sync for ResourceGuard<T>
impl<T> Unpin for ResourceGuard<T>where
T: Unpin,
impl<T> UnsafeUnpin for ResourceGuard<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for ResourceGuard<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more