From 548733e5d5f748664e73f61334c239e51af0b8b8 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sat, 9 Nov 2019 11:22:09 +0100 Subject: [PATCH] Cleanup stream traits (#487) * Cleanup stream traits * Fix docs --- src/collections/binary_heap/from_stream.rs | 8 +-- src/collections/btree_map/from_stream.rs | 8 +-- src/collections/btree_set/from_stream.rs | 8 +-- src/collections/hash_map/from_stream.rs | 8 +-- src/collections/hash_set/from_stream.rs | 8 +-- src/collections/linked_list/from_stream.rs | 8 +-- src/collections/vec_deque/from_stream.rs | 8 +-- src/fs/file_type.rs | 6 +- src/fs/metadata.rs | 16 ++--- src/fs/permissions.rs | 4 +- src/fs/read_dir.rs | 2 +- src/future/future/delay.rs | 2 +- src/future/future/flatten.rs | 7 +-- src/future/into_future.rs | 2 +- src/future/pending.rs | 2 +- src/future/poll_fn.rs | 2 +- src/future/timeout.rs | 2 +- src/io/buf_read/read_line.rs | 2 +- src/io/buf_read/read_until.rs | 2 +- src/io/buf_writer.rs | 3 +- src/io/copy.rs | 2 +- src/io/read/read.rs | 2 +- src/io/read/read_exact.rs | 2 +- src/io/read/read_to_end.rs | 2 +- src/io/read/read_to_string.rs | 2 +- src/io/read/read_vectored.rs | 2 +- src/io/seek/seek.rs | 2 +- src/io/stderr.rs | 2 +- src/io/stdin.rs | 3 +- src/io/stdout.rs | 2 +- src/io/timeout.rs | 2 +- src/io/write/flush.rs | 2 +- src/io/write/write.rs | 2 +- src/io/write/write_all.rs | 2 +- src/io/write/write_fmt.rs | 2 +- src/io/write/write_vectored.rs | 2 +- src/net/addr.rs | 2 +- src/net/tcp/listener.rs | 3 +- src/option/from_stream.rs | 7 +-- src/os/unix/net/listener.rs | 3 +- src/path/pathbuf.rs | 28 ++++----- src/prelude.rs | 2 +- src/result/from_stream.rs | 7 +-- src/stream/extend.rs | 5 +- src/stream/from_fn.rs | 2 +- src/stream/from_iter.rs | 9 ++- src/stream/from_stream.rs | 40 ++++++++----- src/stream/interval.rs | 4 +- src/stream/product.rs | 2 +- src/stream/repeat_with.rs | 2 +- src/stream/stream/all.rs | 2 +- src/stream/stream/any.rs | 2 +- src/stream/stream/cmp.rs | 2 +- src/stream/stream/eq.rs | 2 +- src/stream/stream/find.rs | 2 +- src/stream/stream/find_map.rs | 2 +- src/stream/stream/fold.rs | 2 +- src/stream/stream/for_each.rs | 2 +- src/stream/stream/ge.rs | 2 +- src/stream/stream/gt.rs | 2 +- src/stream/stream/last.rs | 2 +- src/stream/stream/le.rs | 2 +- src/stream/stream/lt.rs | 2 +- src/stream/stream/max_by.rs | 2 +- src/stream/stream/max_by_key.rs | 2 +- src/stream/stream/merge.rs | 1 - src/stream/stream/min.rs | 2 +- src/stream/stream/min_by.rs | 2 +- src/stream/stream/min_by_key.rs | 2 +- src/stream/stream/mod.rs | 2 +- src/stream/stream/ne.rs | 2 +- src/stream/stream/next.rs | 2 +- src/stream/stream/nth.rs | 2 +- src/stream/stream/partial_cmp.rs | 2 +- src/stream/stream/position.rs | 2 +- src/stream/stream/timeout.rs | 2 +- src/stream/stream/try_fold.rs | 2 +- src/stream/stream/try_for_each.rs | 2 +- src/stream/sum.rs | 10 ++-- src/string/extend.rs | 69 +++++++++++++++------- src/string/from_stream.rs | 36 ++++------- src/sync/mutex.rs | 2 +- src/sync/rwlock.rs | 2 +- src/task/block_on.rs | 2 +- src/task/builder.rs | 2 +- src/task/spawn.rs | 3 +- src/task/yield_now.rs | 2 +- src/unit/from_stream.rs | 7 +-- src/vec/from_stream.rs | 31 ++++------ 89 files changed, 229 insertions(+), 249 deletions(-) diff --git a/src/collections/binary_heap/from_stream.rs b/src/collections/binary_heap/from_stream.rs index 99bca20..148a57f 100644 --- a/src/collections/binary_heap/from_stream.rs +++ b/src/collections/binary_heap/from_stream.rs @@ -1,16 +1,14 @@ use std::collections::BinaryHeap; use std::pin::Pin; +use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; impl FromStream for BinaryHeap { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/btree_map/from_stream.rs b/src/collections/btree_map/from_stream.rs index cc94402..e0653ab 100644 --- a/src/collections/btree_map/from_stream.rs +++ b/src/collections/btree_map/from_stream.rs @@ -1,16 +1,14 @@ use std::collections::BTreeMap; use std::pin::Pin; +use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; impl FromStream<(K, V)> for BTreeMap { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/btree_set/from_stream.rs b/src/collections/btree_set/from_stream.rs index 6c88a8d..c4197df 100644 --- a/src/collections/btree_set/from_stream.rs +++ b/src/collections/btree_set/from_stream.rs @@ -1,16 +1,14 @@ use std::collections::BTreeSet; use std::pin::Pin; +use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; impl FromStream for BTreeSet { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/hash_map/from_stream.rs b/src/collections/hash_map/from_stream.rs index c3445e1..bf47d8e 100644 --- a/src/collections/hash_map/from_stream.rs +++ b/src/collections/hash_map/from_stream.rs @@ -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 FromStream<(K, V)> for HashMap @@ -10,12 +11,9 @@ where H: BuildHasher + Default, { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/hash_set/from_stream.rs b/src/collections/hash_set/from_stream.rs index 8afc0db..69b3853 100644 --- a/src/collections/hash_set/from_stream.rs +++ b/src/collections/hash_set/from_stream.rs @@ -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 FromStream for HashSet @@ -10,12 +11,9 @@ where H: BuildHasher + Default, { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/linked_list/from_stream.rs b/src/collections/linked_list/from_stream.rs index 3d4c826..1226247 100644 --- a/src/collections/linked_list/from_stream.rs +++ b/src/collections/linked_list/from_stream.rs @@ -1,16 +1,14 @@ use std::collections::LinkedList; use std::pin::Pin; +use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; impl FromStream for LinkedList { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/vec_deque/from_stream.rs b/src/collections/vec_deque/from_stream.rs index 3a5e585..767ec06 100644 --- a/src/collections/vec_deque/from_stream.rs +++ b/src/collections/vec_deque/from_stream.rs @@ -1,16 +1,14 @@ use std::collections::VecDeque; use std::pin::Pin; +use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; impl FromStream for VecDeque { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/fs/file_type.rs b/src/fs/file_type.rs index 11f47d1..d7ce257 100644 --- a/src/fs/file_type.rs +++ b/src/fs/file_type.rs @@ -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") } } } diff --git a/src/fs/metadata.rs b/src/fs/metadata.rs index 1383ec2..2948016 100644 --- a/src/fs/metadata.rs +++ b/src/fs/metadata.rs @@ -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 { - 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 { - 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 { - unimplemented!() + unreachable!("this impl only appears in the rendered docs") } } } diff --git a/src/fs/permissions.rs b/src/fs/permissions.rs index 1339a7c..50aa45c 100644 --- a/src/fs/permissions.rs +++ b/src/fs/permissions.rs @@ -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") } } } diff --git a/src/fs/read_dir.rs b/src/fs/read_dir.rs index fe12fa6..5e51065 100644 --- a/src/fs/read_dir.rs +++ b/src/fs/read_dir.rs @@ -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; diff --git a/src/future/future/delay.rs b/src/future/future/delay.rs index d672541..45658f4 100644 --- a/src/future/future/delay.rs +++ b/src/future/future/delay.rs @@ -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! { diff --git a/src/future/future/flatten.rs b/src/future/future/flatten.rs index 0e83144..1d31644 100644 --- a/src/future/future/flatten.rs +++ b/src/future/future/flatten.rs @@ -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 { diff --git a/src/future/into_future.rs b/src/future/into_future.rs index 42839a2..a9a8187 100644 --- a/src/future/into_future.rs +++ b/src/future/into_future.rs @@ -1,4 +1,4 @@ -use crate::future::Future; +use std::future::Future; /// Convert a type into a `Future`. /// diff --git a/src/future/pending.rs b/src/future/pending.rs index 2138a30..39f7cab 100644 --- a/src/future/pending.rs +++ b/src/future/pending.rs @@ -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. diff --git a/src/future/poll_fn.rs b/src/future/poll_fn.rs index a808f97..1945264 100644 --- a/src/future/poll_fn.rs +++ b/src/future/poll_fn.rs @@ -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`]. diff --git a/src/future/timeout.rs b/src/future/timeout.rs index c745d73..ff87ae4 100644 --- a/src/future/timeout.rs +++ b/src/future/timeout.rs @@ -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. diff --git a/src/io/buf_read/read_line.rs b/src/io/buf_read/read_line.rs index 04c61c1..b66079b 100644 --- a/src/io/buf_read/read_line.rs +++ b/src/io/buf_read/read_line.rs @@ -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}; diff --git a/src/io/buf_read/read_until.rs b/src/io/buf_read/read_until.rs index 72385ab..bda1eee 100644 --- a/src/io/buf_read/read_until.rs +++ b/src/io/buf_read/read_until.rs @@ -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}; diff --git a/src/io/buf_writer.rs b/src/io/buf_writer.rs index 6327ca7..8fa9eba 100644 --- a/src/io/buf_writer.rs +++ b/src/io/buf_writer.rs @@ -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; diff --git a/src/io/copy.rs b/src/io/copy.rs index 098df8d..753f5e3 100644 --- a/src/io/copy.rs +++ b/src/io/copy.rs @@ -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}; diff --git a/src/io/read/read.rs b/src/io/read/read.rs index c46aff6..0ba04e5 100644 --- a/src/io/read/read.rs +++ b/src/io/read/read.rs @@ -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}; diff --git a/src/io/read/read_exact.rs b/src/io/read/read_exact.rs index c970f43..71cf004 100644 --- a/src/io/read/read_exact.rs +++ b/src/io/read/read_exact.rs @@ -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}; diff --git a/src/io/read/read_to_end.rs b/src/io/read/read_to_end.rs index d76ee8c..c7c47b8 100644 --- a/src/io/read/read_to_end.rs +++ b/src/io/read/read_to_end.rs @@ -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}; diff --git a/src/io/read/read_to_string.rs b/src/io/read/read_to_string.rs index 5f1a4d2..5b74389 100644 --- a/src/io/read/read_to_string.rs +++ b/src/io/read/read_to_string.rs @@ -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}; diff --git a/src/io/read/read_vectored.rs b/src/io/read/read_vectored.rs index 8e52ba2..b4c61b8 100644 --- a/src/io/read/read_vectored.rs +++ b/src/io/read/read_vectored.rs @@ -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}; diff --git a/src/io/seek/seek.rs b/src/io/seek/seek.rs index 65743be..74aa93e 100644 --- a/src/io/seek/seek.rs +++ b/src/io/seek/seek.rs @@ -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}; diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 8bd2180..5ff8a02 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -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}; diff --git a/src/io/stdin.rs b/src/io/stdin.rs index bd6580c..167ea2d 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -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}; diff --git a/src/io/stdout.rs b/src/io/stdout.rs index c0565aa..1711c09 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -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}; diff --git a/src/io/timeout.rs b/src/io/timeout.rs index ec3668e..6e22dbf 100644 --- a/src/io/timeout.rs +++ b/src/io/timeout.rs @@ -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. diff --git a/src/io/write/flush.rs b/src/io/write/flush.rs index 08f2b5b..590c12e 100644 --- a/src/io/write/flush.rs +++ b/src/io/write/flush.rs @@ -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}; diff --git a/src/io/write/write.rs b/src/io/write/write.rs index da6e5c5..8f13091 100644 --- a/src/io/write/write.rs +++ b/src/io/write/write.rs @@ -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}; diff --git a/src/io/write/write_all.rs b/src/io/write/write_all.rs index 5353f7a..f04c55d 100644 --- a/src/io/write/write_all.rs +++ b/src/io/write/write_all.rs @@ -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}; diff --git a/src/io/write/write_fmt.rs b/src/io/write/write_fmt.rs index ad3e94a..ec7847f 100644 --- a/src/io/write/write_fmt.rs +++ b/src/io/write/write_fmt.rs @@ -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}; diff --git a/src/io/write/write_vectored.rs b/src/io/write/write_vectored.rs index 5f8492b..cdb49d4 100644 --- a/src/io/write/write_vectored.rs +++ b/src/io/write/write_vectored.rs @@ -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}; diff --git a/src/net/addr.rs b/src/net/addr.rs index c17ff49..2769dd5 100644 --- a/src/net/addr.rs +++ b/src/net/addr.rs @@ -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}; diff --git a/src/net/tcp/listener.rs b/src/net/tcp/listener.rs index 6fd27f0..f98bbdc 100644 --- a/src/net/tcp/listener.rs +++ b/src/net/tcp/listener.rs @@ -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}; diff --git a/src/option/from_stream.rs b/src/option/from_stream.rs index e4da809..d2d53b6 100644 --- a/src/option/from_stream.rs +++ b/src/option/from_stream.rs @@ -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>>( + fn from_stream<'a, S: IntoStream> + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/os/unix/net/listener.rs b/src/os/unix/net/listener.rs index 9bd86d3..675ef48 100644 --- a/src/os/unix/net/listener.rs +++ b/src/os/unix/net/listener.rs @@ -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}; diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index 12f5ac3..c95103f 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -242,36 +242,30 @@ impl AsRef for PathBuf { #[cfg(feature = "unstable")] impl> stream::Extend

for PathBuf { - fn extend<'a, S: IntoStream>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, - ) -> Pin + 'a>> - where - P: 'a, - ::IntoStream: 'a, - { + ) -> Pin + '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 + 'b> FromStream

for PathBuf { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { - let stream = stream.into_stream(); - + ) -> Pin + 'a>> { Box::pin(async move { + let stream = stream.into_stream(); pin_utils::pin_mut!(stream); let mut out = Self::new(); diff --git a/src/prelude.rs b/src/prelude.rs index 2a1fa41..a2a14a1 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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; diff --git a/src/result/from_stream.rs b/src/result/from_stream.rs index 6033eb9..9296797 100644 --- a/src/result/from_stream.rs +++ b/src/result/from_stream.rs @@ -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>>( + fn from_stream<'a, S: IntoStream> + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/stream/extend.rs b/src/stream/extend.rs index 0d26afa..7bdfd34 100644 --- a/src/stream/extend.rs +++ b/src/stream/extend.rs @@ -34,9 +34,7 @@ pub trait Extend { fn extend<'a, T: IntoStream + 'a>( &'a mut self, stream: T, - ) -> Pin + 'a>> - where - A: 'a; + ) -> Pin + 'a>>; } /// Extends a collection with the contents of a stream. @@ -70,7 +68,6 @@ pub trait Extend { pub async fn extend<'a, C, A, T>(collection: &mut C, stream: T) where C: Extend, - A: 'a, T: IntoStream + 'a, { Extend::extend(collection, stream).await diff --git a/src/stream/from_fn.rs b/src/stream/from_fn.rs index 5260d87..a28a901 100644 --- a/src/stream/from_fn.rs +++ b/src/stream/from_fn.rs @@ -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}; diff --git a/src/stream/from_iter.rs b/src/stream/from_iter.rs index 5fd216d..a83afce 100644 --- a/src/stream/from_iter.rs +++ b/src/stream/from_iter.rs @@ -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(iter: I) -> FromIter<::IntoIter> { +/// ``` +pub fn from_iter(iter: I) -> FromIter { FromIter { iter: iter.into_iter(), } diff --git a/src/stream/from_stream.rs b/src/stream/from_stream.rs index 6e5200a..67b9b3d 100644 --- a/src/stream/from_stream.rs +++ b/src/stream/from_stream.rs @@ -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,21 +16,24 @@ 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}; +/// # +/// 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(()) }) } /// ``` /// /// 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 for MyCollection { /// fn from_stream<'a, S: IntoStream + 'a>( /// stream: S, -/// ) -> Pin + 'a>> { +/// ) -> Pin + '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,17 +121,19 @@ pub trait FromStream { /// /// ``` /// # 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(()) }) } /// ``` fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>>; + ) -> Pin + 'a>>; } diff --git a/src/stream/interval.rs b/src/stream/interval.rs index efec436..b0df714 100644 --- a/src/stream/interval.rs +++ b/src/stream/interval.rs @@ -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 diff --git a/src/stream/product.rs b/src/stream/product.rs index 71b14c7..2f5bf4c 100644 --- a/src/stream/product.rs +++ b/src/stream/product.rs @@ -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. diff --git a/src/stream/repeat_with.rs b/src/stream/repeat_with.rs index de53bc9..6e7cfa3 100644 --- a/src/stream/repeat_with.rs +++ b/src/stream/repeat_with.rs @@ -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}; diff --git a/src/stream/stream/all.rs b/src/stream/stream/all.rs index 3b65fc7..7b84abe 100644 --- a/src/stream/stream/all.rs +++ b/src/stream/stream/all.rs @@ -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}; diff --git a/src/stream/stream/any.rs b/src/stream/stream/any.rs index a23adf4..c7fc766 100644 --- a/src/stream/stream/any.rs +++ b/src/stream/stream/any.rs @@ -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}; diff --git a/src/stream/stream/cmp.rs b/src/stream/stream/cmp.rs index df08e9d..19437e7 100644 --- a/src/stream/stream/cmp.rs +++ b/src/stream/stream/cmp.rs @@ -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}; diff --git a/src/stream/stream/eq.rs b/src/stream/stream/eq.rs index 5343c1a..addcfa2 100644 --- a/src/stream/stream/eq.rs +++ b/src/stream/stream/eq.rs @@ -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}; diff --git a/src/stream/stream/find.rs b/src/stream/stream/find.rs index 93624c0..b37a6a4 100644 --- a/src/stream/stream/find.rs +++ b/src/stream/stream/find.rs @@ -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}; diff --git a/src/stream/stream/find_map.rs b/src/stream/stream/find_map.rs index dfcf92d..16993fc 100644 --- a/src/stream/stream/find_map.rs +++ b/src/stream/stream/find_map.rs @@ -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)] diff --git a/src/stream/stream/fold.rs b/src/stream/stream/fold.rs index 5b0eb12..66a7672 100644 --- a/src/stream/stream/fold.rs +++ b/src/stream/stream/fold.rs @@ -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}; diff --git a/src/stream/stream/for_each.rs b/src/stream/stream/for_each.rs index 4696529..6383ed7 100644 --- a/src/stream/stream/for_each.rs +++ b/src/stream/stream/for_each.rs @@ -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}; diff --git a/src/stream/stream/ge.rs b/src/stream/stream/ge.rs index 3dc6031..f901269 100644 --- a/src/stream/stream/ge.rs +++ b/src/stream/stream/ge.rs @@ -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}; diff --git a/src/stream/stream/gt.rs b/src/stream/stream/gt.rs index 513ca76..81e95a1 100644 --- a/src/stream/stream/gt.rs +++ b/src/stream/stream/gt.rs @@ -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}; diff --git a/src/stream/stream/last.rs b/src/stream/stream/last.rs index eba01e5..188da3c 100644 --- a/src/stream/stream/last.rs +++ b/src/stream/stream/last.rs @@ -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}; diff --git a/src/stream/stream/le.rs b/src/stream/stream/le.rs index af72700..35b04bf 100644 --- a/src/stream/stream/le.rs +++ b/src/stream/stream/le.rs @@ -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}; diff --git a/src/stream/stream/lt.rs b/src/stream/stream/lt.rs index 524f268..86c3129 100644 --- a/src/stream/stream/lt.rs +++ b/src/stream/stream/lt.rs @@ -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}; diff --git a/src/stream/stream/max_by.rs b/src/stream/stream/max_by.rs index a626b28..cfba9b9 100644 --- a/src/stream/stream/max_by.rs +++ b/src/stream/stream/max_by.rs @@ -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}; diff --git a/src/stream/stream/max_by_key.rs b/src/stream/stream/max_by_key.rs index b3fb65b..b5bc7e0 100644 --- a/src/stream/stream/max_by_key.rs +++ b/src/stream/stream/max_by_key.rs @@ -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}; diff --git a/src/stream/stream/merge.rs b/src/stream/stream/merge.rs index f3505ac..fe3579e 100644 --- a/src/stream/stream/merge.rs +++ b/src/stream/stream/merge.rs @@ -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::*; diff --git a/src/stream/stream/min.rs b/src/stream/stream/min.rs index b4a8c7c..4ce52be 100644 --- a/src/stream/stream/min.rs +++ b/src/stream/stream/min.rs @@ -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}; diff --git a/src/stream/stream/min_by.rs b/src/stream/stream/min_by.rs index ab12aa0..fc332c2 100644 --- a/src/stream/stream/min_by.rs +++ b/src/stream/stream/min_by.rs @@ -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}; diff --git a/src/stream/stream/min_by_key.rs b/src/stream/stream/min_by_key.rs index 6557f22..8179fb3 100644 --- a/src/stream/stream/min_by_key.rs +++ b/src/stream/stream/min_by_key.rs @@ -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}; diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index d0d6935..76130bb 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -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}; diff --git a/src/stream/stream/ne.rs b/src/stream/stream/ne.rs index ffeaca8..ec11d1f 100644 --- a/src/stream/stream/ne.rs +++ b/src/stream/stream/ne.rs @@ -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}; diff --git a/src/stream/stream/next.rs b/src/stream/stream/next.rs index de75f5e..23abb0b 100644 --- a/src/stream/stream/next.rs +++ b/src/stream/stream/next.rs @@ -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}; diff --git a/src/stream/stream/nth.rs b/src/stream/stream/nth.rs index e7e042a..711287a 100644 --- a/src/stream/stream/nth.rs +++ b/src/stream/stream/nth.rs @@ -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)] diff --git a/src/stream/stream/partial_cmp.rs b/src/stream/stream/partial_cmp.rs index e30c6ea..6bc28f7 100644 --- a/src/stream/stream/partial_cmp.rs +++ b/src/stream/stream/partial_cmp.rs @@ -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}; diff --git a/src/stream/stream/position.rs b/src/stream/stream/position.rs index 3cd5b84..3d8f40d 100644 --- a/src/stream/stream/position.rs +++ b/src/stream/stream/position.rs @@ -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}; diff --git a/src/stream/stream/timeout.rs b/src/stream/stream/timeout.rs index 3c14811..636e406 100644 --- a/src/stream/stream/timeout.rs +++ b/src/stream/stream/timeout.rs @@ -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}; diff --git a/src/stream/stream/try_fold.rs b/src/stream/stream/try_fold.rs index 80392e1..bf92ff5 100644 --- a/src/stream/stream/try_fold.rs +++ b/src/stream/stream/try_fold.rs @@ -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}; diff --git a/src/stream/stream/try_for_each.rs b/src/stream/stream/try_for_each.rs index 6b66d2e..36198f9 100644 --- a/src/stream/stream/try_for_each.rs +++ b/src/stream/stream/try_for_each.rs @@ -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}; diff --git a/src/stream/sum.rs b/src/stream/sum.rs index dadbc34..9607baf 100644 --- a/src/stream/sum.rs +++ b/src/stream/sum.rs @@ -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: Sized { S: Stream + '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 } diff --git a/src/string/extend.rs b/src/string/extend.rs index 769f1ec..55bec0c 100644 --- a/src/string/extend.rs +++ b/src/string/extend.rs @@ -10,25 +10,32 @@ impl stream::Extend for String { stream: S, ) -> Pin + '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 + 'a>( &'a mut self, - //TODO: Remove the underscore when uncommenting the body of this impl - _stream: S, - ) -> Pin + '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 + '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 + 'a>( &'a mut self, stream: S, - ) -> Pin + 'a>> - where - 'b: 'a, - { - Box::pin(stream.into_stream().for_each(move |s| self.push_str(s))) + ) -> Pin + '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 for String { &'a mut self, stream: S, ) -> Pin + '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> for String { fn extend<'a, S: IntoStream> + 'a>( &'a mut self, stream: S, - ) -> Pin + 'a>> - where - 'b: 'a, - { - Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s))) + ) -> Pin + '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); + } + }) } } diff --git a/src/string/from_stream.rs b/src/string/from_stream.rs index e0b2da9..eb6818c 100644 --- a/src/string/from_stream.rs +++ b/src/string/from_stream.rs @@ -1,16 +1,14 @@ use std::borrow::Cow; use std::pin::Pin; +use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; impl FromStream for String { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { @@ -25,12 +23,9 @@ impl FromStream for String { impl<'b> FromStream<&'b char> for String { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + '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>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { @@ -65,12 +57,9 @@ impl<'b> FromStream<&'b str> for String { impl FromStream for String { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { @@ -85,12 +74,9 @@ impl FromStream for String { impl<'b> FromStream> for String { #[inline] - fn from_stream<'a, S: IntoStream>>( + fn from_stream<'a, S: IntoStream> + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/sync/mutex.rs b/src/sync/mutex.rs index 52c3898..5bec6a2 100644 --- a/src/sync/mutex.rs +++ b/src/sync/mutex.rs @@ -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}; diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index e042bbd..bc3f640 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -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}; diff --git a/src/task/block_on.rs b/src/task/block_on.rs index d320cb2..f61a22b 100644 --- a/src/task/block_on.rs +++ b/src/task/block_on.rs @@ -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. diff --git a/src/task/builder.rs b/src/task/builder.rs index a61d785..afd4c2c 100644 --- a/src/task/builder.rs +++ b/src/task/builder.rs @@ -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}; diff --git a/src/task/spawn.rs b/src/task/spawn.rs index da2957b..f81a483 100644 --- a/src/task/spawn.rs +++ b/src/task/spawn.rs @@ -1,4 +1,5 @@ -use crate::future::Future; +use std::future::Future; + use crate::task::{Builder, JoinHandle}; /// Spawns a task. diff --git a/src/task/yield_now.rs b/src/task/yield_now.rs index 5cd0ce5..03f83e2 100644 --- a/src/task/yield_now.rs +++ b/src/task/yield_now.rs @@ -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. diff --git a/src/unit/from_stream.rs b/src/unit/from_stream.rs index a238982..da216e2 100644 --- a/src/unit/from_stream.rs +++ b/src/unit/from_stream.rs @@ -5,12 +5,9 @@ use crate::stream::{FromStream, IntoStream}; impl FromStream<()> for () { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { Box::pin(stream.into_stream().for_each(|_| ())) } } diff --git a/src/vec/from_stream.rs b/src/vec/from_stream.rs index 7b6cda1..cdd4767 100644 --- a/src/vec/from_stream.rs +++ b/src/vec/from_stream.rs @@ -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 FromStream for Vec { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, - ) -> Pin + 'a>> + ) -> Pin + 'a>> where ::IntoStream: 'a, { @@ -27,12 +28,9 @@ impl FromStream for Vec { impl<'b, T: Clone> FromStream for Cow<'b, [T]> { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { @@ -45,12 +43,9 @@ impl<'b, T: Clone> FromStream for Cow<'b, [T]> { impl FromStream for Box<[T]> { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { @@ -63,12 +58,9 @@ impl FromStream for Box<[T]> { impl FromStream for Rc<[T]> { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move { @@ -81,12 +73,9 @@ impl FromStream for Rc<[T]> { impl FromStream for Arc<[T]> { #[inline] - fn from_stream<'a, S: IntoStream>( + fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> - where - ::IntoStream: 'a, - { + ) -> Pin + 'a>> { let stream = stream.into_stream(); Box::pin(async move {