usecrate::sync::CancellationToken;/// A wrapper for cancellation token which automatically cancels
/// it on drop. It is created using [`drop_guard`] method on the [`CancellationToken`].
////// [`drop_guard`]: CancellationToken::drop_guard
#[derive(Debug)]pubstructDropGuard{pub(super) inner:Option<CancellationToken>,
}implDropGuard{/// Returns stored cancellation token and removes this drop guard instance
/// (i.e. it will no longer cancel token). Other guards for this token
/// are not affected.
pubfndisarm(mutself)-> CancellationToken{self.inner
.take().expect("`inner` can be only None in a destructor")}}implDrop forDropGuard{fndrop(&mutself){ifletSome(inner)=&self.inner {
inner.cancel();}}}