Cleanup stream traits (#487)

* Cleanup stream traits

* Fix docs
poc-serde-support
Stjepan Glavina 5 years ago committed by GitHub
parent 4a78f731b7
commit 548733e5d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,16 +1,14 @@
use std::collections::BinaryHeap;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<T: Ord> FromStream<T> for BinaryHeap<T> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -1,16 +1,14 @@
use std::collections::BTreeMap;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<K: Ord, V> FromStream<(K, V)> for BTreeMap<K, V> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = (K, V)>>(
fn from_stream<'a, S: IntoStream<Item = (K, V)> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -1,16 +1,14 @@
use std::collections::BTreeSet;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<T: Ord> FromStream<T> for BTreeSet<T> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::hash::{BuildHasher, Hash};
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<K, V, H> FromStream<(K, V)> for HashMap<K, V, H>
@ -10,12 +11,9 @@ where
H: BuildHasher + Default,
{
#[inline]
fn from_stream<'a, S: IntoStream<Item = (K, V)>>(
fn from_stream<'a, S: IntoStream<Item = (K, V)> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -2,6 +2,7 @@ use std::collections::HashSet;
use std::hash::{BuildHasher, Hash};
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<T, H> FromStream<T> for HashSet<T, H>
@ -10,12 +11,9 @@ where
H: BuildHasher + Default,
{
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -1,16 +1,14 @@
use std::collections::LinkedList;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<T> FromStream<T> for LinkedList<T> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -1,16 +1,14 @@
use std::collections::VecDeque;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<T> FromStream<T> for VecDeque<T> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -40,7 +40,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn is_dir(&self) -> bool {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns `true` if this file type represents a regular file.
@ -60,7 +60,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn is_file(&self) -> bool {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns `true` if this file type represents a symbolic link.
@ -78,7 +78,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn is_symlink(&self) -> bool {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
}
}

@ -78,7 +78,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn file_type(&self) -> FileType {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns `true` if this metadata is for a regular directory.
@ -98,7 +98,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn is_dir(&self) -> bool {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns `true` if this metadata is for a regular file.
@ -118,7 +118,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn is_file(&self) -> bool {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns the file size in bytes.
@ -136,7 +136,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn len(&self) -> u64 {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns the permissions from this metadata.
@ -154,7 +154,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn permissions(&self) -> Permissions {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns the last modification time.
@ -177,7 +177,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn modified(&self) -> io::Result<SystemTime> {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns the last access time.
@ -200,7 +200,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn accessed(&self) -> io::Result<SystemTime> {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Returns the creation time.
@ -223,7 +223,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn created(&self) -> io::Result<SystemTime> {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
}
}

@ -29,7 +29,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn readonly(&self) -> bool {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
/// Configures the read-only flag.
@ -50,7 +50,7 @@ cfg_docs! {
/// # Ok(()) }) }
/// ```
pub fn set_readonly(&mut self, readonly: bool) {
unimplemented!()
unreachable!("this impl only appears in the rendered docs")
}
}
}

@ -1,7 +1,7 @@
use std::pin::Pin;
use std::future::Future;
use crate::fs::DirEntry;
use crate::future::Future;
use crate::io;
use crate::path::Path;
use crate::stream::Stream;

@ -1,10 +1,10 @@
use std::pin::Pin;
use std::time::Duration;
use std::future::Future;
use futures_timer::Delay;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::task::{Context, Poll};
pin_project! {

@ -1,9 +1,8 @@
use futures_core::ready;
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::future::IntoFuture;
use crate::task::{Context, Poll};
use crate::future::{IntoFuture};
use crate::task::{ready, Context, Poll};
#[derive(Debug)]
pub struct FlattenFuture<Fut1, Fut2> {

@ -1,4 +1,4 @@
use crate::future::Future;
use std::future::Future;
/// Convert a type into a `Future`.
///

@ -1,7 +1,7 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::task::{Context, Poll};
/// Never resolves to a value.

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::task::{Context, Poll};
/// Creates a new future wrapping around a function returning [`Poll`].

@ -2,11 +2,11 @@ use std::error::Error;
use std::fmt;
use std::pin::Pin;
use std::time::Duration;
use std::future::Future;
use futures_timer::Delay;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::task::{Context, Poll};
/// Awaits a future or times out after a duration of time.

@ -1,9 +1,9 @@
use std::mem;
use std::pin::Pin;
use std::str;
use std::future::Future;
use super::read_until_internal;
use crate::future::Future;
use crate::io::{self, BufRead};
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::pin::Pin;
use std::future::Future;
use super::read_until_internal;
use crate::future::Future;
use crate::io::{self, BufRead};
use crate::task::{Context, Poll};

@ -1,12 +1,11 @@
use std::fmt;
use std::pin::Pin;
use futures_core::ready;
use pin_project_lite::pin_project;
use crate::io::write::WriteExt;
use crate::io::{self, Seek, SeekFrom, Write};
use crate::task::{Context, Poll};
use crate::task::{Context, Poll, ready};
const DEFAULT_CAPACITY: usize = 8 * 1024;

@ -1,8 +1,8 @@
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::io::{self, BufRead, BufReader, Read, Write};
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Read};
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::mem;
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Read};
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Read};
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::mem;
use std::pin::Pin;
use std::str;
use std::future::Future;
use super::read_to_end_internal;
use crate::future::Future;
use crate::io::{self, Read};
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, IoSliceMut, Read};
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Seek, SeekFrom};
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::pin::Pin;
use std::sync::Mutex;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Write};
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};

@ -1,7 +1,8 @@
use std::pin::Pin;
use std::sync::Mutex;
use std::future::Future;
use crate::future::{self, Future};
use crate::future;
use crate::io::{self, Read};
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};

@ -1,7 +1,7 @@
use std::pin::Pin;
use std::sync::Mutex;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Write};
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};

@ -1,11 +1,11 @@
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use std::future::Future;
use futures_timer::Delay;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::io;
/// Awaits an I/O future or times out after a duration of time.

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Write};
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Write};
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::mem;
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Write};
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, Write};
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io::{self, IoSlice, Write};
use crate::task::{Context, Poll};

@ -2,8 +2,8 @@ use std::mem;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::io;
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};

@ -1,7 +1,8 @@
use std::net::SocketAddr;
use std::future::Future;
use std::pin::Pin;
use crate::future::{self, Future};
use crate::future;
use crate::io;
use crate::net::driver::Watcher;
use crate::net::{TcpStream, ToSocketAddrs};

@ -11,12 +11,9 @@ where
/// elements are taken, and `None` is returned. Should no `None`
/// occur, a container with the values of each `Option` is returned.
#[inline]
fn from_stream<'a, S: IntoStream<Item = Option<T>>>(
fn from_stream<'a, S: IntoStream<Item = Option<T>> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -2,12 +2,13 @@
use std::fmt;
use std::pin::Pin;
use std::future::Future;
use mio_uds;
use super::SocketAddr;
use super::UnixStream;
use crate::future::{self, Future};
use crate::future;
use crate::io;
use crate::net::driver::Watcher;
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};

@ -242,36 +242,30 @@ impl AsRef<std::path::Path> for PathBuf {
#[cfg(feature = "unstable")]
impl<P: AsRef<Path>> stream::Extend<P> for PathBuf {
fn extend<'a, S: IntoStream<Item = P>>(
fn extend<'a, S: IntoStream<Item = P> + 'a>(
&'a mut self,
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>>
where
P: 'a,
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
let stream = stream.into_stream();
//TODO: This can be added back in once this issue is resolved:
// https://github.com/rust-lang/rust/issues/58234
//self.reserve(stream.size_hint().0);
Box::pin(async move {
pin_utils::pin_mut!(stream);
Box::pin(stream.for_each(move |item| self.push(item.as_ref())))
while let Some(item) = stream.next().await {
self.push(item.as_ref());
}
})
}
}
#[cfg(feature = "unstable")]
impl<'b, P: AsRef<Path> + 'b> FromStream<P> for PathBuf {
#[inline]
fn from_stream<'a, S: IntoStream<Item = P>>(
fn from_stream<'a, S: IntoStream<Item = P> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream();
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
Box::pin(async move {
let stream = stream.into_stream();
pin_utils::pin_mut!(stream);
let mut out = Self::new();

@ -13,7 +13,7 @@
cfg_std! {
#[doc(no_inline)]
pub use crate::future::Future;
pub use std::future::Future;
#[doc(no_inline)]
pub use crate::stream::Stream;

@ -11,12 +11,9 @@ where
/// elements are taken, and the `Err` is returned. Should no `Err`
/// occur, a container with the values of each `Result` is returned.
#[inline]
fn from_stream<'a, S: IntoStream<Item = Result<T, E>>>(
fn from_stream<'a, S: IntoStream<Item = Result<T, E>> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -34,9 +34,7 @@ pub trait Extend<A> {
fn extend<'a, T: IntoStream<Item = A> + 'a>(
&'a mut self,
stream: T,
) -> Pin<Box<dyn Future<Output = ()> + 'a>>
where
A: 'a;
) -> Pin<Box<dyn Future<Output = ()> + 'a>>;
}
/// Extends a collection with the contents of a stream.
@ -70,7 +68,6 @@ pub trait Extend<A> {
pub async fn extend<'a, C, A, T>(collection: &mut C, stream: T)
where
C: Extend<A>,
A: 'a,
T: IntoStream<Item = A> + 'a,
{
Extend::extend(collection, stream).await

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -18,8 +18,11 @@ pin_project! {
}
}
/// Converts an iterator into a stream.
///
/// # Examples
///```
///
/// ```
/// # async_std::task::block_on(async {
/// #
/// use async_std::prelude::*;
@ -34,8 +37,8 @@ pin_project! {
/// assert_eq!(s.next().await, None);
/// #
/// # })
///````
pub fn from_iter<I: IntoIterator>(iter: I) -> FromIter<<I as std::iter::IntoIterator>::IntoIter> {
/// ```
pub fn from_iter<I: IntoIterator>(iter: I) -> FromIter<I::IntoIter> {
FromIter {
iter: iter.into_iter(),
}

@ -1,7 +1,8 @@
use super::IntoStream;
use std::future::Future;
use std::pin::Pin;
use crate::stream::IntoStream;
/// Conversion from a `Stream`.
///
/// By implementing `FromStream` for a type, you define how it will be created from a stream.
@ -15,6 +16,7 @@ use std::pin::Pin;
///
/// ```
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::prelude::*;
/// use async_std::stream::{self, FromStream};
///
@ -23,13 +25,15 @@ use std::pin::Pin;
/// let v = Vec::from_stream(five_fives).await;
///
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// #
/// # Ok(()) }) }
/// ```
///
/// Using `collect` to implicitly use `FromStream`
///
///```
/// ```
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::prelude::*;
/// use async_std::stream;
/// let five_fives = stream::repeat(5).take(5);
@ -39,7 +43,7 @@ use std::pin::Pin;
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// #
/// # Ok(()) }) }
///```
/// ```
///
/// Implementing `FromStream` for your type:
///
@ -68,7 +72,7 @@ use std::pin::Pin;
/// impl FromStream<i32> for MyCollection {
/// fn from_stream<'a, S: IntoStream<Item = i32> + 'a>(
/// stream: S,
/// ) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>> {
/// ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
/// let stream = stream.into_stream();
///
/// Box::pin(async move {
@ -86,6 +90,7 @@ use std::pin::Pin;
/// }
///
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// // Now we can make a new stream...
/// let stream = stream::repeat(5).take(5);
///
@ -100,6 +105,7 @@ use std::pin::Pin;
/// let c: MyCollection = stream.collect().await;
///
/// assert_eq!(c.0, vec![5, 5, 5, 5, 5]);
/// #
/// # Ok(()) }) }
///```
///
@ -115,6 +121,7 @@ pub trait FromStream<T> {
///
/// ```
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::prelude::*;
/// use async_std::stream::{self, FromStream};
///
@ -123,9 +130,10 @@ pub trait FromStream<T> {
/// let v = Vec::from_stream(five_fives).await;
///
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// #
/// # Ok(()) }) }
/// ```
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>;
) -> Pin<Box<dyn Future<Output = Self> + 'a>>;
}

@ -2,10 +2,10 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
use futures_core::future::Future;
use futures_core::stream::Stream;
use futures_timer::Delay;
use crate::prelude::*;
/// Creates a new stream that yields at a set interval.
///
/// The stream first yields after `dur`, and continues to yield every

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream;
/// Trait to represent types that can be created by multiplying the elements of a stream.

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,10 +1,10 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use super::fuse::Fuse;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use super::fuse::Fuse;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,8 +1,8 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream;
#[doc(hidden)]

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,10 +1,10 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use super::partial_cmp::PartialCmpFuture;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,10 +1,10 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use super::partial_cmp::PartialCmpFuture;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,8 +1,8 @@
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,10 +1,10 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use super::partial_cmp::PartialCmpFuture;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,10 +1,10 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use super::partial_cmp::PartialCmpFuture;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,7 +1,6 @@
use std::pin::Pin;
use std::task::{Context, Poll};
use futures_core::Stream;
use pin_project_lite::pin_project;
use crate::prelude::*;

@ -1,10 +1,10 @@
use std::cmp::{Ord, Ordering};
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::cmp::Ordering;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -112,10 +112,10 @@ use std::cmp::Ordering;
use std::marker::PhantomData;
cfg_unstable! {
use std::future::Future;
use std::pin::Pin;
use std::time::Duration;
use crate::future::Future;
use crate::stream::into_stream::IntoStream;
use crate::stream::{FromStream, Product, Sum};

@ -1,9 +1,9 @@
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use super::fuse::Fuse;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,7 +1,7 @@
use std::pin::Pin;
use std::task::{Context, Poll};
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream;
#[doc(hidden)]

@ -1,10 +1,10 @@
use std::cmp::Ordering;
use std::future::Future;
use std::pin::Pin;
use pin_project_lite::pin_project;
use super::fuse::Fuse;
use crate::future::Future;
use crate::prelude::*;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,8 +1,8 @@
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -2,11 +2,11 @@ use std::error::Error;
use std::fmt;
use std::pin::Pin;
use std::time::Duration;
use std::future::Future;
use futures_timer::Delay;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::marker::PhantomData;
use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,9 +1,9 @@
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream;
use crate::task::{Context, Poll};

@ -1,6 +1,6 @@
use std::future::Future;
use std::pin::Pin;
use crate::future::Future;
use crate::stream::Stream;
/// Trait to represent types that can be created by summing up a stream.
@ -23,9 +23,9 @@ pub trait Sum<A = Self>: Sized {
S: Stream<Item = A> + 'a;
}
use core::ops::Add;
use core::num::Wrapping;
use crate::stream::stream::StreamExt;
use core::num::Wrapping;
use core::ops::Add;
macro_rules! integer_sum {
(@impls $zero: expr, $($a:ty)*) => ($(
@ -75,5 +75,5 @@ macro_rules! float_sum {
);
}
integer_sum!{ i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
float_sum!{ f32 f64 }
integer_sum! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
float_sum! { f32 f64 }

@ -10,25 +10,32 @@ impl stream::Extend<char> for String {
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
let stream = stream.into_stream();
self.reserve(stream.size_hint().0);
Box::pin(stream.for_each(move |c| self.push(c)))
Box::pin(async move {
pin_utils::pin_mut!(stream);
while let Some(item) = stream.next().await {
self.push(item);
}
})
}
}
impl<'b> stream::Extend<&'b char> for String {
fn extend<'a, S: IntoStream<Item = &'b char> + 'a>(
&'a mut self,
//TODO: Remove the underscore when uncommenting the body of this impl
_stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>>
where
'b: 'a,
{
//TODO: This can be uncommented when `copied` is added to Stream/StreamExt
//Box::pin(stream.into_stream().copied())
unimplemented!()
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
pin_utils::pin_mut!(stream);
while let Some(item) = stream.next().await {
self.push(*item);
}
})
}
}
@ -36,11 +43,16 @@ impl<'b> stream::Extend<&'b str> for String {
fn extend<'a, S: IntoStream<Item = &'b str> + 'a>(
&'a mut self,
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>>
where
'b: 'a,
{
Box::pin(stream.into_stream().for_each(move |s| self.push_str(s)))
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
pin_utils::pin_mut!(stream);
while let Some(item) = stream.next().await {
self.push_str(item);
}
})
}
}
@ -49,7 +61,15 @@ impl stream::Extend<String> for String {
&'a mut self,
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s)))
let stream = stream.into_stream();
Box::pin(async move {
pin_utils::pin_mut!(stream);
while let Some(item) = stream.next().await {
self.push_str(&item);
}
})
}
}
@ -57,10 +77,15 @@ impl<'b> stream::Extend<Cow<'b, str>> for String {
fn extend<'a, S: IntoStream<Item = Cow<'b, str>> + 'a>(
&'a mut self,
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>>
where
'b: 'a,
{
Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s)))
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
pin_utils::pin_mut!(stream);
while let Some(item) = stream.next().await {
self.push_str(&item);
}
})
}
}

@ -1,16 +1,14 @@
use std::borrow::Cow;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl FromStream<char> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = char>>(
fn from_stream<'a, S: IntoStream<Item = char> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
@ -25,12 +23,9 @@ impl FromStream<char> for String {
impl<'b> FromStream<&'b char> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = &'b char>>(
fn from_stream<'a, S: IntoStream<Item = &'b char> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
@ -45,12 +40,9 @@ impl<'b> FromStream<&'b char> for String {
impl<'b> FromStream<&'b str> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = &'b str>>(
fn from_stream<'a, S: IntoStream<Item = &'b str> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
@ -65,12 +57,9 @@ impl<'b> FromStream<&'b str> for String {
impl FromStream<String> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = String>>(
fn from_stream<'a, S: IntoStream<Item = String> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
@ -85,12 +74,9 @@ impl FromStream<String> for String {
impl<'b> FromStream<Cow<'b, str>> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = Cow<'b, str>>>(
fn from_stream<'a, S: IntoStream<Item = Cow<'b, str>> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

@ -3,8 +3,8 @@ use std::fmt;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
use std::future::Future;
use crate::future::Future;
use crate::sync::WakerSet;
use crate::task::{Context, Poll};

@ -4,9 +4,9 @@ use std::isize;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::process;
use std::future::Future;
use std::sync::atomic::{AtomicUsize, Ordering};
use crate::future::Future;
use crate::sync::WakerSet;
use crate::task::{Context, Poll};

@ -1,4 +1,5 @@
use std::cell::Cell;
use std::future::Future;
use std::mem::{self, ManuallyDrop};
use std::sync::Arc;
use std::task::{RawWaker, RawWakerVTable};
@ -8,7 +9,6 @@ use crossbeam_utils::sync::Parker;
use kv_log_macro::trace;
use log::log_enabled;
use crate::future::Future;
use crate::task::{Context, Poll, Task, Waker};
/// Spawns a task and blocks the current thread on its result.

@ -1,7 +1,7 @@
use kv_log_macro::trace;
use log::log_enabled;
use std::future::Future;
use crate::future::Future;
use crate::io;
use crate::task::executor;
use crate::task::{JoinHandle, Task};

@ -1,4 +1,5 @@
use crate::future::Future;
use std::future::Future;
use crate::task::{Builder, JoinHandle};
/// Spawns a task.

@ -1,6 +1,6 @@
use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::task::{Context, Poll};
/// Cooperatively gives up a timeslice to the task scheduler.

@ -5,12 +5,9 @@ use crate::stream::{FromStream, IntoStream};
impl FromStream<()> for () {
#[inline]
fn from_stream<'a, S: IntoStream<Item = ()>>(
fn from_stream<'a, S: IntoStream<Item = ()> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
Box::pin(stream.into_stream().for_each(|_| ()))
}
}

@ -3,13 +3,14 @@ use std::pin::Pin;
use std::rc::Rc;
use std::sync::Arc;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl<T> FromStream<T> for Vec<T> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
) -> Pin<Box<dyn Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
@ -27,12 +28,9 @@ impl<T> FromStream<T> for Vec<T> {
impl<'b, T: Clone> FromStream<T> for Cow<'b, [T]> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
@ -45,12 +43,9 @@ impl<'b, T: Clone> FromStream<T> for Cow<'b, [T]> {
impl<T> FromStream<T> for Box<[T]> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
@ -63,12 +58,9 @@ impl<T> FromStream<T> for Box<[T]> {
impl<T> FromStream<T> for Rc<[T]> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {
@ -81,12 +73,9 @@ impl<T> FromStream<T> for Rc<[T]> {
impl<T> FromStream<T> for Arc<[T]> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
let stream = stream.into_stream();
Box::pin(async move {

Loading…
Cancel
Save