From 9fdbb4839da91f19fd88dce58b81305be1671f25 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Fri, 12 Jul 2019 21:32:16 +0200 Subject: [PATCH] fixup! A cancel guard --- src/core/scheduler.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/scheduler.rs b/src/core/scheduler.rs index b3cdfbb..f8ecbd3 100644 --- a/src/core/scheduler.rs +++ b/src/core/scheduler.rs @@ -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 { + // This is Option, so disarm can work. + // The problem is, Rust won't let us destructure self because we have a destructor. inner: Option, } @@ -22,8 +24,8 @@ impl CancelGuard { /// /// 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") } }