sync: implement cancellation token getter for drop guard (#8226)

This commit is contained in:
Matteo Monti
2026-06-24 15:16:23 +02:00
committed by GitHub
parent 95b8895da8
commit dba1f20585
2 changed files with 14 additions and 0 deletions
@@ -10,6 +10,13 @@ pub struct DropGuard {
}
impl DropGuard {
/// Returns a reference to the cancellation token wrapped by this guard.
pub fn token(&self) -> &CancellationToken {
self.inner
.as_ref()
.expect("`inner` can only be None in a destructor")
}
/// 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.
@@ -13,6 +13,13 @@ pub struct DropGuardRef<'a> {
}
impl<'a> DropGuardRef<'a> {
/// Returns a reference to the cancellation token wrapped by this guard.
pub fn token(&self) -> &CancellationToken {
self.inner
.as_ref()
.expect("`inner` can only be None in a destructor")
}
/// 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.