Skip to content

Commit b57792d

Browse files
committed
Wrap IntoFuture around Cancellable::future
Implement IntoFuture for Cancellable and &Cancellable as a dead-simple wrapper around the existing Cancellable::future. See #1512
1 parent fec12a0 commit b57792d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

gio/src/cancellable.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3-
use std::num::NonZeroU64;
3+
use std::{future::IntoFuture, num::NonZeroU64};
44

55
use futures_channel::oneshot;
66
use futures_core::Future;
@@ -146,6 +146,26 @@ pub trait CancellableExtManual: IsA<Cancellable> {
146146

147147
impl<O: IsA<Cancellable>> CancellableExtManual for O {}
148148

149+
impl IntoFuture for Cancellable {
150+
type Output = ();
151+
152+
type IntoFuture = std::pin::Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
153+
154+
fn into_future(self) -> Self::IntoFuture {
155+
self.future()
156+
}
157+
}
158+
159+
impl IntoFuture for &Cancellable {
160+
type Output = ();
161+
162+
type IntoFuture = std::pin::Pin<Box<dyn Future<Output = ()> + Send + Sync + 'static>>;
163+
164+
fn into_future(self) -> Self::IntoFuture {
165+
self.future()
166+
}
167+
}
168+
149169
#[cfg(test)]
150170
mod tests {
151171
use super::*;

0 commit comments

Comments
 (0)