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

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

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

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

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

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

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

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

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

@ -29,7 +29,7 @@ cfg_docs! {
/// # Ok(()) }) } /// # Ok(()) }) }
/// ``` /// ```
pub fn readonly(&self) -> bool { pub fn readonly(&self) -> bool {
unimplemented!() unreachable!("this impl only appears in the rendered docs")
} }
/// Configures the read-only flag. /// Configures the read-only flag.
@ -50,7 +50,7 @@ cfg_docs! {
/// # Ok(()) }) } /// # Ok(()) }) }
/// ``` /// ```
pub fn set_readonly(&mut self, readonly: bool) { 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::pin::Pin;
use std::future::Future;
use crate::fs::DirEntry; use crate::fs::DirEntry;
use crate::future::Future;
use crate::io; use crate::io;
use crate::path::Path; use crate::path::Path;
use crate::stream::Stream; use crate::stream::Stream;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -18,8 +18,11 @@ pin_project! {
} }
} }
/// Converts an iterator into a stream.
///
/// # Examples /// # Examples
///``` ///
/// ```
/// # async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::prelude::*; /// use async_std::prelude::*;
@ -34,8 +37,8 @@ pin_project! {
/// assert_eq!(s.next().await, None); /// 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 { FromIter {
iter: iter.into_iter(), iter: iter.into_iter(),
} }

@ -1,7 +1,8 @@
use super::IntoStream; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use crate::stream::IntoStream;
/// Conversion from a `Stream`. /// Conversion from a `Stream`.
/// ///
/// By implementing `FromStream` for a type, you define how it will be created from a stream. /// By implementing `FromStream` for a type, you define how it will be created from a stream.
@ -15,21 +16,24 @@ use std::pin::Pin;
/// ///
/// ``` /// ```
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// use async_std::prelude::*; /// #
/// use async_std::stream::{self, FromStream}; /// use async_std::prelude::*;
/// use async_std::stream::{self, FromStream};
/// ///
/// let five_fives = stream::repeat(5).take(5); /// let five_fives = stream::repeat(5).take(5);
/// ///
/// let v = Vec::from_stream(five_fives).await; /// let v = Vec::from_stream(five_fives).await;
/// ///
/// assert_eq!(v, vec![5, 5, 5, 5, 5]); /// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// #
/// # Ok(()) }) } /// # Ok(()) }) }
/// ``` /// ```
/// ///
/// Using `collect` to implicitly use `FromStream` /// Using `collect` to implicitly use `FromStream`
/// ///
///``` /// ```
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::prelude::*; /// use async_std::prelude::*;
/// use async_std::stream; /// use async_std::stream;
/// let five_fives = stream::repeat(5).take(5); /// 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]); /// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// # /// #
/// # Ok(()) }) } /// # Ok(()) }) }
///``` /// ```
/// ///
/// Implementing `FromStream` for your type: /// Implementing `FromStream` for your type:
/// ///
@ -68,7 +72,7 @@ use std::pin::Pin;
/// impl FromStream<i32> for MyCollection { /// impl FromStream<i32> for MyCollection {
/// fn from_stream<'a, S: IntoStream<Item = i32> + 'a>( /// fn from_stream<'a, S: IntoStream<Item = i32> + 'a>(
/// stream: S, /// stream: S,
/// ) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>> { /// ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
/// let stream = stream.into_stream(); /// let stream = stream.into_stream();
/// ///
/// Box::pin(async move { /// Box::pin(async move {
@ -86,6 +90,7 @@ use std::pin::Pin;
/// } /// }
/// ///
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// // Now we can make a new stream... /// // Now we can make a new stream...
/// let stream = stream::repeat(5).take(5); /// let stream = stream::repeat(5).take(5);
/// ///
@ -100,6 +105,7 @@ use std::pin::Pin;
/// let c: MyCollection = stream.collect().await; /// let c: MyCollection = stream.collect().await;
/// ///
/// assert_eq!(c.0, vec![5, 5, 5, 5, 5]); /// assert_eq!(c.0, vec![5, 5, 5, 5, 5]);
/// #
/// # Ok(()) }) } /// # Ok(()) }) }
///``` ///```
/// ///
@ -115,17 +121,19 @@ pub trait FromStream<T> {
/// ///
/// ``` /// ```
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// use async_std::prelude::*; /// #
/// use async_std::stream::{self, FromStream}; /// use async_std::prelude::*;
/// use async_std::stream::{self, FromStream};
/// ///
/// let five_fives = stream::repeat(5).take(5); /// let five_fives = stream::repeat(5).take(5);
/// ///
/// let v = Vec::from_stream(five_fives).await; /// let v = Vec::from_stream(five_fives).await;
/// ///
/// assert_eq!(v, vec![5, 5, 5, 5, 5]); /// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// #
/// # Ok(()) }) } /// # Ok(()) }) }
/// ``` /// ```
fn from_stream<'a, S: IntoStream<Item = T> + 'a>( fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
stream: S, 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::task::{Context, Poll};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use futures_core::future::Future;
use futures_core::stream::Stream;
use futures_timer::Delay; use futures_timer::Delay;
use crate::prelude::*;
/// Creates a new stream that yields at a set interval. /// Creates a new stream that yields at a set interval.
/// ///
/// The stream first yields after `dur`, and continues to yield every /// The stream first yields after `dur`, and continues to yield every

@ -1,6 +1,6 @@
use std::pin::Pin; use std::pin::Pin;
use std::future::Future;
use crate::future::Future;
use crate::stream::Stream; use crate::stream::Stream;
/// Trait to represent types that can be created by multiplying the elements of a 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::marker::PhantomData;
use std::pin::Pin; use std::pin::Pin;
use std::future::Future;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use crate::future::Future;
use crate::stream::Stream; use crate::stream::Stream;
use crate::task::{Context, Poll}; use crate::task::{Context, Poll};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -10,25 +10,32 @@ impl stream::Extend<char> for String {
stream: S, stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> { ) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
let stream = stream.into_stream(); let stream = stream.into_stream();
self.reserve(stream.size_hint().0); 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 { impl<'b> stream::Extend<&'b char> for String {
fn extend<'a, S: IntoStream<Item = &'b char> + 'a>( fn extend<'a, S: IntoStream<Item = &'b char> + 'a>(
&'a mut self, &'a mut self,
//TODO: Remove the underscore when uncommenting the body of this impl stream: S,
_stream: S, ) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
) -> Pin<Box<dyn Future<Output = ()> + 'a>> let stream = stream.into_stream();
where
'b: 'a, Box::pin(async move {
{ pin_utils::pin_mut!(stream);
//TODO: This can be uncommented when `copied` is added to Stream/StreamExt
//Box::pin(stream.into_stream().copied()) while let Some(item) = stream.next().await {
unimplemented!() self.push(*item);
}
})
} }
} }
@ -36,11 +43,16 @@ impl<'b> stream::Extend<&'b str> for String {
fn extend<'a, S: IntoStream<Item = &'b str> + 'a>( fn extend<'a, S: IntoStream<Item = &'b str> + 'a>(
&'a mut self, &'a mut self,
stream: S, stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> ) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
where let stream = stream.into_stream();
'b: 'a,
{ Box::pin(async move {
Box::pin(stream.into_stream().for_each(move |s| self.push_str(s))) 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, &'a mut self,
stream: S, stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> { ) -> 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>( fn extend<'a, S: IntoStream<Item = Cow<'b, str>> + 'a>(
&'a mut self, &'a mut self,
stream: S, stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> ) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
where let stream = stream.into_stream();
'b: 'a,
{ Box::pin(async move {
Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s))) 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::borrow::Cow;
use std::pin::Pin; use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream}; use crate::stream::{self, FromStream, IntoStream};
impl FromStream<char> for String { impl FromStream<char> for String {
#[inline] #[inline]
fn from_stream<'a, S: IntoStream<Item = char>>( fn from_stream<'a, S: IntoStream<Item = char> + 'a>(
stream: S, stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>> ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream(); let stream = stream.into_stream();
Box::pin(async move { Box::pin(async move {
@ -25,12 +23,9 @@ impl FromStream<char> for String {
impl<'b> FromStream<&'b char> for String { impl<'b> FromStream<&'b char> for String {
#[inline] #[inline]
fn from_stream<'a, S: IntoStream<Item = &'b char>>( fn from_stream<'a, S: IntoStream<Item = &'b char> + 'a>(
stream: S, stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>> ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream(); let stream = stream.into_stream();
Box::pin(async move { Box::pin(async move {
@ -45,12 +40,9 @@ impl<'b> FromStream<&'b char> for String {
impl<'b> FromStream<&'b str> for String { impl<'b> FromStream<&'b str> for String {
#[inline] #[inline]
fn from_stream<'a, S: IntoStream<Item = &'b str>>( fn from_stream<'a, S: IntoStream<Item = &'b str> + 'a>(
stream: S, stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>> ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream(); let stream = stream.into_stream();
Box::pin(async move { Box::pin(async move {
@ -65,12 +57,9 @@ impl<'b> FromStream<&'b str> for String {
impl FromStream<String> for String { impl FromStream<String> for String {
#[inline] #[inline]
fn from_stream<'a, S: IntoStream<Item = String>>( fn from_stream<'a, S: IntoStream<Item = String> + 'a>(
stream: S, stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>> ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream(); let stream = stream.into_stream();
Box::pin(async move { Box::pin(async move {
@ -85,12 +74,9 @@ impl FromStream<String> for String {
impl<'b> FromStream<Cow<'b, str>> for String { impl<'b> FromStream<Cow<'b, str>> for String {
#[inline] #[inline]
fn from_stream<'a, S: IntoStream<Item = Cow<'b, str>>>( fn from_stream<'a, S: IntoStream<Item = Cow<'b, str>> + 'a>(
stream: S, stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>> ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream(); let stream = stream.into_stream();
Box::pin(async move { Box::pin(async move {

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

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

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

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

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

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

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

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

Loading…
Cancel
Save