pub struct CancelGuard<C: Cancellable> { /* private fields */ }Expand description
A guard that cancels a source when dropped, unless disarmed.
This provides RAII-style cancellation for cleanup on error paths or panics.
Create one via the StopDropRoll trait.
§Example
use almost_enough::{Stopper, StopDropRoll};
let source = Stopper::new();
{
let guard = source.stop_on_drop();
// guard dropped here, source gets cancelled
}
assert!(source.is_cancelled());§Disarming
Call disarm() to prevent cancellation:
use almost_enough::{Stopper, StopDropRoll};
let source = Stopper::new();
{
let guard = source.stop_on_drop();
guard.disarm(); // Prevents cancellation
}
assert!(!source.is_cancelled());Implementations§
Source§impl<C: Cancellable> CancelGuard<C>
impl<C: Cancellable> CancelGuard<C>
Sourcepub fn new(source: C) -> Self
pub fn new(source: C) -> Self
Create a new guard that will cancel the source on drop.
Prefer using StopDropRoll::stop_on_drop() instead.
Sourcepub fn disarm(self)
pub fn disarm(self)
Disarm the guard, preventing cancellation on drop.
Call this when the guarded operation succeeds and you don’t want to cancel.
§Example
use almost_enough::{Stopper, StopDropRoll};
let source = Stopper::new();
let guard = source.stop_on_drop();
// Operation succeeded, don't cancel
guard.disarm(); // Consumes guard, preventing cancellation
assert!(!source.is_cancelled());Trait Implementations§
Source§impl<C: Debug + Cancellable> Debug for CancelGuard<C>
impl<C: Debug + Cancellable> Debug for CancelGuard<C>
Source§impl<C: Cancellable> Drop for CancelGuard<C>
impl<C: Cancellable> Drop for CancelGuard<C>
Auto Trait Implementations§
impl<C> Freeze for CancelGuard<C>where
C: Freeze,
impl<C> RefUnwindSafe for CancelGuard<C>where
C: RefUnwindSafe,
impl<C> Send for CancelGuard<C>
impl<C> Sync for CancelGuard<C>where
C: Sync,
impl<C> Unpin for CancelGuard<C>where
C: Unpin,
impl<C> UnwindSafe for CancelGuard<C>where
C: UnwindSafe,
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