diff options
author | Lucio Franco <luciofranco14@gmail.com> | 2020-04-17 15:37:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 15:37:59 -0400 |
commit | 19a87e090ed528001e0363a30f6165304a710d49 (patch) | |
tree | 6ea451ae5aedaf0bb7a6b9e90d477e5bdcb1b4af /tokio-test/src | |
parent | 6f00d7158bd03961e0bbab464b8b6e218bfe3833 (diff) |
test: Add `Future` and `Stream` impl for `Spawn`. (#2412)
Diffstat (limited to 'tokio-test/src')
-rw-r--r-- | tokio-test/src/lib.rs | 2 | ||||
-rw-r--r-- | tokio-test/src/task.rs | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/tokio-test/src/lib.rs b/tokio-test/src/lib.rs index c109c148..185f317b 100644 --- a/tokio-test/src/lib.rs +++ b/tokio-test/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/tokio-test/0.2.0")] +#![doc(html_root_url = "https://docs.rs/tokio-test/0.2.1")] #![warn( missing_debug_implementations, missing_docs, diff --git a/tokio-test/src/task.rs b/tokio-test/src/task.rs index 04328e3d..b31850ba 100644 --- a/tokio-test/src/task.rs +++ b/tokio-test/src/task.rs @@ -116,6 +116,26 @@ impl<T: Stream> Spawn<T> { } } +impl<T: Future> Future for Spawn<T> { + type Output = T::Output; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { + // Safety: we only expose &mut T if T: Unpin therefore this is safe. + let future = unsafe { self.map_unchecked_mut(|s| &mut s.future) }; + future.poll(cx) + } +} + +impl<T: Stream> Stream for Spawn<T> { + type Item = T::Item; + + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { + // Safety: we only expose &mut T if T: Unpin therefore this is safe. + let stream = unsafe { self.map_unchecked_mut(|s| &mut s.future) }; + stream.poll_next(cx) + } +} + impl MockTask { /// Creates new mock task fn new() -> Self { |