forked from mirror/async-std
fix: Stabilize stream method
This commit is contained in:
parent
9a62df143f
commit
f31878655e
9 changed files with 63 additions and 44 deletions
|
@ -35,7 +35,7 @@ default = [
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
docs = ["attributes", "unstable", "default"]
|
docs = ["attributes", "unstable", "default"]
|
||||||
unstable = ["std", "broadcaster", "futures-timer"]
|
unstable = ["std", "broadcaster"]
|
||||||
attributes = ["async-attributes"]
|
attributes = ["async-attributes"]
|
||||||
std = [
|
std = [
|
||||||
"alloc",
|
"alloc",
|
||||||
|
|
|
@ -38,16 +38,14 @@ cfg_std! {
|
||||||
pub use crate::io::prelude::SeekExt as _;
|
pub use crate::io::prelude::SeekExt as _;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use crate::io::prelude::WriteExt as _;
|
pub use crate::io::prelude::WriteExt as _;
|
||||||
|
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use crate::stream::DoubleEndedStream;
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use crate::stream::ExactSizeStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_default! {
|
cfg_default! {
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use crate::task_local;
|
pub use crate::task_local;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_unstable! {
|
|
||||||
#[doc(no_inline)]
|
|
||||||
pub use crate::stream::DoubleEndedStream;
|
|
||||||
#[doc(no_inline)]
|
|
||||||
pub use crate::stream::ExactSizeStream;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::stream::Stream;
|
use crate::stream::Stream;
|
||||||
|
|
||||||
use std::pin::Pin;
|
use core::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use core::task::{Context, Poll};
|
||||||
|
|
||||||
mod next_back;
|
mod next_back;
|
||||||
mod nth_back;
|
mod nth_back;
|
||||||
|
|
|
@ -300,39 +300,42 @@
|
||||||
//! [`take`]: trait.Stream.html#method.take
|
//! [`take`]: trait.Stream.html#method.take
|
||||||
//! [`min`]: trait.Stream.html#method.min
|
//! [`min`]: trait.Stream.html#method.min
|
||||||
|
|
||||||
pub use double_ended_stream::DoubleEndedStream;
|
|
||||||
pub use empty::{empty, Empty};
|
pub use empty::{empty, Empty};
|
||||||
pub use exact_size_stream::ExactSizeStream;
|
|
||||||
pub use from_fn::{from_fn, FromFn};
|
pub use from_fn::{from_fn, FromFn};
|
||||||
pub use from_iter::{from_iter, FromIter};
|
pub use from_iter::{from_iter, FromIter};
|
||||||
pub use fused_stream::FusedStream;
|
|
||||||
pub use interval::{interval, Interval};
|
|
||||||
pub use once::{once, Once};
|
pub use once::{once, Once};
|
||||||
pub use pending::{pending, Pending};
|
|
||||||
pub use product::Product;
|
|
||||||
pub use repeat::{repeat, Repeat};
|
pub use repeat::{repeat, Repeat};
|
||||||
pub use repeat_with::{repeat_with, RepeatWith};
|
pub use repeat_with::{repeat_with, RepeatWith};
|
||||||
pub use stream::Merge;
|
|
||||||
pub use stream::*;
|
pub use stream::*;
|
||||||
pub use successors::{successors, Successors};
|
|
||||||
pub use sum::Sum;
|
|
||||||
|
|
||||||
pub(crate) mod stream;
|
pub(crate) mod stream;
|
||||||
|
|
||||||
mod double_ended_stream;
|
|
||||||
mod empty;
|
mod empty;
|
||||||
mod exact_size_stream;
|
|
||||||
mod from_fn;
|
mod from_fn;
|
||||||
mod from_iter;
|
mod from_iter;
|
||||||
mod fused_stream;
|
|
||||||
mod interval;
|
|
||||||
mod once;
|
mod once;
|
||||||
mod pending;
|
|
||||||
mod product;
|
|
||||||
mod repeat;
|
mod repeat;
|
||||||
mod repeat_with;
|
mod repeat_with;
|
||||||
mod successors;
|
|
||||||
mod sum;
|
cfg_std! {
|
||||||
|
pub use double_ended_stream::DoubleEndedStream;
|
||||||
|
pub use exact_size_stream::ExactSizeStream;
|
||||||
|
pub use fused_stream::FusedStream;
|
||||||
|
pub use interval::{interval, Interval};
|
||||||
|
pub use pending::{pending, Pending};
|
||||||
|
pub use product::Product;
|
||||||
|
pub use successors::{successors, Successors};
|
||||||
|
pub use sum::Sum;
|
||||||
|
|
||||||
|
mod double_ended_stream;
|
||||||
|
mod exact_size_stream;
|
||||||
|
mod fused_stream;
|
||||||
|
mod interval;
|
||||||
|
mod pending;
|
||||||
|
mod product;
|
||||||
|
mod successors;
|
||||||
|
mod sum;
|
||||||
|
}
|
||||||
|
|
||||||
cfg_unstable! {
|
cfg_unstable! {
|
||||||
mod from_stream;
|
mod from_stream;
|
||||||
|
|
|
@ -5,6 +5,7 @@ use pin_project_lite::pin_project;
|
||||||
use crate::stream::Stream;
|
use crate::stream::Stream;
|
||||||
use crate::task::{Context, Poll};
|
use crate::task::{Context, Poll};
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
use crate::stream::DoubleEndedStream;
|
use crate::stream::DoubleEndedStream;
|
||||||
|
|
||||||
/// Creates a stream that yields a single item.
|
/// Creates a stream that yields a single item.
|
||||||
|
@ -49,6 +50,7 @@ impl<T> Stream for Once<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
impl<T> DoubleEndedStream for Once<T> {
|
impl<T> DoubleEndedStream for Once<T> {
|
||||||
fn poll_next_back(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next_back(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
Poll::Ready(self.project().value.take())
|
Poll::Ready(self.project().value.take())
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use alloc::boxed::Box;
|
||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,7 @@ mod chain;
|
||||||
mod cloned;
|
mod cloned;
|
||||||
mod cmp;
|
mod cmp;
|
||||||
mod copied;
|
mod copied;
|
||||||
mod count;
|
|
||||||
mod cycle;
|
mod cycle;
|
||||||
mod delay;
|
|
||||||
mod enumerate;
|
mod enumerate;
|
||||||
mod eq;
|
mod eq;
|
||||||
mod filter;
|
mod filter;
|
||||||
|
@ -49,7 +47,6 @@ mod map;
|
||||||
mod max;
|
mod max;
|
||||||
mod max_by;
|
mod max_by;
|
||||||
mod max_by_key;
|
mod max_by_key;
|
||||||
mod merge;
|
|
||||||
mod min;
|
mod min;
|
||||||
mod min_by;
|
mod min_by;
|
||||||
mod min_by_key;
|
mod min_by_key;
|
||||||
|
@ -64,17 +61,13 @@ mod skip_while;
|
||||||
mod step_by;
|
mod step_by;
|
||||||
mod take;
|
mod take;
|
||||||
mod take_while;
|
mod take_while;
|
||||||
mod throttle;
|
|
||||||
mod timeout;
|
|
||||||
mod try_fold;
|
mod try_fold;
|
||||||
mod try_for_each;
|
mod try_for_each;
|
||||||
mod unzip;
|
|
||||||
mod zip;
|
mod zip;
|
||||||
|
|
||||||
use all::AllFuture;
|
use all::AllFuture;
|
||||||
use any::AnyFuture;
|
use any::AnyFuture;
|
||||||
use cmp::CmpFuture;
|
use cmp::CmpFuture;
|
||||||
use count::CountFuture;
|
|
||||||
use cycle::Cycle;
|
use cycle::Cycle;
|
||||||
use enumerate::Enumerate;
|
use enumerate::Enumerate;
|
||||||
use eq::EqFuture;
|
use eq::EqFuture;
|
||||||
|
@ -101,33 +94,46 @@ use partial_cmp::PartialCmpFuture;
|
||||||
use position::PositionFuture;
|
use position::PositionFuture;
|
||||||
use try_fold::TryFoldFuture;
|
use try_fold::TryFoldFuture;
|
||||||
use try_for_each::TryForEachFuture;
|
use try_for_each::TryForEachFuture;
|
||||||
use unzip::UnzipFuture;
|
|
||||||
|
|
||||||
pub use chain::Chain;
|
pub use chain::Chain;
|
||||||
pub use cloned::Cloned;
|
pub use cloned::Cloned;
|
||||||
pub use copied::Copied;
|
pub use copied::Copied;
|
||||||
pub use delay::Delay;
|
|
||||||
pub use filter::Filter;
|
pub use filter::Filter;
|
||||||
pub use fuse::Fuse;
|
pub use fuse::Fuse;
|
||||||
pub use inspect::Inspect;
|
pub use inspect::Inspect;
|
||||||
pub use map::Map;
|
pub use map::Map;
|
||||||
pub use merge::Merge;
|
|
||||||
pub use scan::Scan;
|
pub use scan::Scan;
|
||||||
pub use skip::Skip;
|
pub use skip::Skip;
|
||||||
pub use skip_while::SkipWhile;
|
pub use skip_while::SkipWhile;
|
||||||
pub use step_by::StepBy;
|
pub use step_by::StepBy;
|
||||||
pub use take::Take;
|
pub use take::Take;
|
||||||
pub use take_while::TakeWhile;
|
pub use take_while::TakeWhile;
|
||||||
pub use throttle::Throttle;
|
|
||||||
pub use timeout::{Timeout, TimeoutError};
|
|
||||||
pub use zip::Zip;
|
pub use zip::Zip;
|
||||||
|
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::future::Future;
|
|
||||||
use core::pin::Pin;
|
|
||||||
use core::time::Duration;
|
|
||||||
|
|
||||||
use crate::stream::{Product, Sum};
|
cfg_std! {
|
||||||
|
use core::time::Duration;
|
||||||
|
use crate::stream::{Product, Sum};
|
||||||
|
use alloc::boxed::Box;
|
||||||
|
use core::future::Future;
|
||||||
|
use core::pin::Pin;
|
||||||
|
|
||||||
|
use unzip::UnzipFuture;
|
||||||
|
use count::CountFuture;
|
||||||
|
|
||||||
|
pub use throttle::Throttle;
|
||||||
|
pub use merge::Merge;
|
||||||
|
pub use delay::Delay;
|
||||||
|
pub use timeout::{Timeout, TimeoutError};
|
||||||
|
|
||||||
|
mod timeout;
|
||||||
|
mod throttle;
|
||||||
|
mod merge;
|
||||||
|
mod delay;
|
||||||
|
mod unzip;
|
||||||
|
mod count;
|
||||||
|
}
|
||||||
|
|
||||||
cfg_unstable! {
|
cfg_unstable! {
|
||||||
use crate::stream::FromStream;
|
use crate::stream::FromStream;
|
||||||
|
@ -357,6 +363,7 @@ extension_trait! {
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn throttle(self, d: Duration) -> Throttle<Self>
|
fn throttle(self, d: Duration) -> Throttle<Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
@ -598,6 +605,7 @@ extension_trait! {
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn delay(self, dur: std::time::Duration) -> Delay<Self>
|
fn delay(self, dur: std::time::Duration) -> Delay<Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
@ -1652,6 +1660,7 @@ extension_trait! {
|
||||||
# Ok(()) }) }
|
# Ok(()) }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn timeout(self, dur: Duration) -> Timeout<Self>
|
fn timeout(self, dur: Duration) -> Timeout<Self>
|
||||||
where
|
where
|
||||||
Self: Stream + Sized,
|
Self: Stream + Sized,
|
||||||
|
@ -1816,6 +1825,7 @@ extension_trait! {
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn unzip<A, B, FromA, FromB>(self) -> impl Future<Output = (FromA, FromB)> [UnzipFuture<Self, FromA, FromB>]
|
fn unzip<A, B, FromA, FromB>(self) -> impl Future<Output = (FromA, FromB)> [UnzipFuture<Self, FromA, FromB>]
|
||||||
where
|
where
|
||||||
FromA: Default + Extend<A>,
|
FromA: Default + Extend<A>,
|
||||||
|
@ -1913,6 +1923,7 @@ extension_trait! {
|
||||||
# });
|
# });
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn merge<U>(self, other: U) -> Merge<Self, U>
|
fn merge<U>(self, other: U) -> Merge<Self, U>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
@ -2058,6 +2069,7 @@ extension_trait! {
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn count(self) -> impl Future<Output = usize> [CountFuture<Self>]
|
fn count(self) -> impl Future<Output = usize> [CountFuture<Self>]
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
@ -2318,6 +2330,7 @@ extension_trait! {
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn sum<'a, S>(
|
fn sum<'a, S>(
|
||||||
self,
|
self,
|
||||||
) -> impl Future<Output = S> + 'a [Pin<Box<dyn Future<Output = S> + 'a>>]
|
) -> impl Future<Output = S> + 'a [Pin<Box<dyn Future<Output = S> + 'a>>]
|
||||||
|
@ -2362,6 +2375,7 @@ extension_trait! {
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn product<'a, P>(
|
fn product<'a, P>(
|
||||||
self,
|
self,
|
||||||
) -> impl Future<Output = P> + 'a [Pin<Box<dyn Future<Output = P> + 'a>>]
|
) -> impl Future<Output = P> + 'a [Pin<Box<dyn Future<Output = P> + 'a>>]
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use alloc::boxed::Box;
|
||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub fn abort_on_panic<T>(f: impl FnOnce() -> T) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a random number in `0..n`.
|
/// Generates a random number in `0..n`.
|
||||||
#[cfg(any(feature = "unstable", feature = "default"))]
|
#[cfg(any(feature = "std", feature = "default"))]
|
||||||
pub fn random(n: u32) -> u32 {
|
pub fn random(n: u32) -> u32 {
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
|
|
Loading…
Reference in a new issue