mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
test: Add Future and Stream impl for Spawn. (#2412)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user