mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
test: Add Future
and Stream
impl for Spawn
. (#2412)
This commit is contained in:
parent
6f00d7158b
commit
19a87e090e
@ -1,3 +1,7 @@
|
|||||||
|
# 0.2.1 (April 17, 2020)
|
||||||
|
|
||||||
|
- Add `Future` and `Stream` implementations for `task::Spawn<T>`.
|
||||||
|
|
||||||
# 0.2.0 (November 25, 2019)
|
# 0.2.0 (November 25, 2019)
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
|
@ -7,13 +7,13 @@ name = "tokio-test"
|
|||||||
# - Cargo.toml
|
# - Cargo.toml
|
||||||
# - Update CHANGELOG.md.
|
# - Update CHANGELOG.md.
|
||||||
# - Create "v0.2.x" git tag.
|
# - Create "v0.2.x" git tag.
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
authors = ["Tokio Contributors <team@tokio.rs>"]
|
authors = ["Tokio Contributors <team@tokio.rs>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/tokio-rs/tokio"
|
repository = "https://github.com/tokio-rs/tokio"
|
||||||
homepage = "https://tokio.rs"
|
homepage = "https://tokio.rs"
|
||||||
documentation = "https://docs.rs/tokio-test/0.2.0/tokio_test"
|
documentation = "https://docs.rs/tokio-test/0.2.1/tokio_test"
|
||||||
description = """
|
description = """
|
||||||
Testing utilities for Tokio- and futures-based code
|
Testing utilities for Tokio- and futures-based code
|
||||||
"""
|
"""
|
||||||
|
@ -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(
|
#![warn(
|
||||||
missing_debug_implementations,
|
missing_debug_implementations,
|
||||||
missing_docs,
|
missing_docs,
|
||||||
|
@ -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 {
|
impl MockTask {
|
||||||
/// Creates new mock task
|
/// Creates new mock task
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user