fixup! A cancel guard

This commit is contained in:
Michal 'vorner' Vaner 2019-07-12 21:32:16 +02:00
parent 35572454d4
commit 9fdbb4839d
No known key found for this signature in database
GPG Key ID: F700D0C019E4C66F
1 changed files with 4 additions and 2 deletions

View File

@ -14,6 +14,8 @@ use std::time::{Duration, Instant};
///
/// See [Cancel::into_guard](trait.Cancel.html#method.into_guard) to create it.
pub struct CancelGuard<C: Cancel> {
// This is Option, so disarm can work.
// The problem is, Rust won't let us destructure self because we have a destructor.
inner: Option<C>,
}
@ -22,8 +24,8 @@ impl<C: Cancel> CancelGuard<C> {
///
/// This disposes of the guard without performing the cancelation. This is similar to calling
/// `forget` on it, but doesn't leak resources, while forget potentially could.
pub fn disarm(mut self) {
self.inner.take();
pub fn disarm(mut self) -> C {
self.inner.take().expect("The borrowchecker shouldn't allow anyone to call disarm twice")
}
}