Yoshua Wuyts
9ff0750d4d
Merge pull request #353 from async-rs/fix-printing
...
fix print macros
2019-10-16 15:07:33 +02:00
Yoshua Wuyts
4d34a15363
fix macros, take II
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-16 14:35:10 +02:00
Yoshua Wuyts
822e4bc220
Merge branch 'master' into fs-stream-repeat-with
2019-10-16 14:26:20 +02:00
Yoshua Wuyts
6e0905d3ca
correctly mark stream::Merge as unstable ( #352 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-16 14:13:35 +02:00
k-nasa
10f32ca817
Fix TimeoutError
2019-10-16 20:21:45 +09:00
Johannes Weissmann
aaa1b6ca39
add Stream::last ( #347 )
...
* add stream::LastFuture (not compiling)
Struggling with the associated type, pinning and how to move/copy
LastFuture.last.
* fix type signature -> still cannot assign
still problems assigning the new value to self.last
* remove unused bound
* add doctest
* unpin LastFuture.last
* RustFmt
* add static lifetime
* remove redundant lifetime
2019-10-16 13:14:54 +02:00
k-nasa
358d2bc038
Add import crate
2019-10-16 19:57:03 +09:00
Stjepan Glavina
add6863185
Fix typos
2019-10-16 12:24:18 +02:00
k-nasa
b251fc999a
Move delay method to FutureExt::delay
2019-10-16 19:18:05 +09:00
Yoshua Wuyts
faff1f7370
task docs ( #346 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-16 10:28:14 +02:00
k-nasa
054f4fac74
feat: Add future::delay
2019-10-16 16:53:43 +09:00
k-nasa
7a87dea085
feat: Add Stream::timeout
2019-10-16 15:31:40 +09:00
k-nasa
f00d32ee7d
Add TimeoutStream struct
2019-10-16 15:31:40 +09:00
Yoshua Wuyts
e986e7ba66
Merge pull request #345 from async-rs/io-docs
...
Io docs
2019-10-16 02:53:38 +02:00
Wouter Geraedts
6b00e5e66c
Implemented StreamExt::try_fold ( #344 )
2019-10-16 02:32:27 +02:00
assemblaj
4b96ea1273
Adds Stream::cmp ( #273 )
...
* Adds cmp
* Fixes formatting
* cleans up examples
* attempts to fix rustdoc issue
* formats with cargo fmt
* Adds proper trait bounds for cmp
2019-10-16 02:23:41 +02:00
Yoshua Wuyts
d250eee556
port the std::io docs to async_std::io
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-16 02:15:20 +02:00
Yoshua Wuyts
9f8fa45dc7
io docs
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-16 02:03:26 +02:00
assemblaj
a7041be6f2
Adds Stream:ge ( #285 )
...
* Adds partial_cmp.rs file and partial_cmp signature to mod.rs
* adds tests that compare streams of same length
* Adds Stream::ge
* cargo fmt
* fixes rustdoc error
2019-10-16 01:24:27 +02:00
assemblaj
5f7238eec6
[Draft PR] Adds Stream::gt ( #304 )
...
* [Draft PR] Adds Stream::gt
* Applies cargo format and fixes incorrect comment
* cargo fmt
* fixes rustdoc related issues
2019-10-16 01:11:48 +02:00
assemblaj
f0f279ec04
Adds Stream::le ( #336 )
2019-10-16 00:46:06 +02:00
assemblaj
a8dc2c6f9b
Adds Stream::lt ( #337 )
2019-10-16 00:32:54 +02:00
Yoshua Wuyts
24cdb2d489
add stream::{Sum,Product} ( #343 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-16 00:31:49 +02:00
Yoshua Wuyts
00d936488b
stabilize future::timeout ( #335 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 16:33:23 +02:00
Yoshua Wuyts
49faea2023
init FutureExt ( #308 )
...
* init FutureExt
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* prelude
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* Refactor extension_trait
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* Fix rustdoc
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 16:27:06 +02:00
Yoshua Wuyts
d46364c834
Merge pull request #299 from async-rs/blocking-updates
...
Blocking updates
2019-10-15 16:17:07 +02:00
Yoshua Wuyts
237cfa0315
add IntoFuture ( #259 )
...
* add IntoFuture
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* blanket impl for IntoFuture
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* cargo fmt
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* example
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* mark as unstable
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 16:03:49 +02:00
Yoshua Wuyts
33806ad44c
fix warning
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 16:01:26 +02:00
Yoshua Wuyts
12fdc1232d
rename task::blocking to task::spawn_blocking
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 16:01:26 +02:00
Yoshua Wuyts
b4c1c63fd2
task::blocking async closure -> FnOnce
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 16:01:24 +02:00
Yoshua Wuyts
1a3429655c
init blocking-updates
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 16:00:15 +02:00
Fedor Sakharov
23beab4125
Adds a from_fn stream implementation ( #277 )
...
* Adds a from_fn stream implementation
* Update src/stream/from_fn.rs
Co-Authored-By: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
* Fix review nits
* Use async_std Mutex
2019-10-15 15:50:17 +02:00
Yoshua Wuyts
e938527f66
add stream::interval ( #298 )
...
* add stream::interval
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* fix tests
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* cargo fmt
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* cross-docs
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* update deps
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 15:30:24 +02:00
Wouter Geraedts
c7f6543502
Inline TryFutureExt logic for src/io/timeout.rs ( #317 )
2019-10-15 09:56:39 +02:00
Yoshua Wuyts
1819408b46
add stream::ExactSizeStream as unstable ( #330 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-15 09:51:53 +02:00
Johannes Weissmann
6be8467cdc
impl Stream::take_while adapter ( #332 )
...
* impl take_while stream adapter
* fmt
* add comment
* unindent where clauses
2019-10-15 09:50:03 +02:00
Yoshua Wuyts
529a58a066
Merge pull request #327 from assemblaj/assemblaj-partial_cmp_final
...
Adds Stream::partial_cmp
2019-10-15 03:45:21 +02:00
Yoshua Wuyts
00a8433338
Merge pull request #320 from Wassasin/183-async-path
...
Implement async Path & PathBuf
2019-10-15 02:51:55 +02:00
Stjepan Glavina
aa13ba758b
Refactor
2019-10-15 02:05:23 +02:00
Stjepan Glavina
5c1e0522b7
Fix failing tests
2019-10-15 01:33:36 +02:00
Stjepan Glavina
504f8cb137
Use crate::path everywhere
2019-10-15 01:25:20 +02:00
Stjepan Glavina
f9cfee9e2c
Formatting
2019-10-15 01:11:32 +02:00
Stjepan Glavina
0adcb50f58
Add ToOwned and Borrow impls
2019-10-15 01:08:12 +02:00
Wouter Geraedts
ba87048db5
Implemented our own Path::ancestors iterator
2019-10-14 22:00:45 +02:00
assemblaj
80bee9a215
Adds Stream::partial_cmp
2019-10-14 11:43:00 -04:00
Yoshua Wuyts
612a94b31e
Add process submodule as unstable ( #310 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-14 15:51:47 +02:00
Yoshua Wuyts
e1deaa58d8
Add BufRead::split ( #312 )
...
* add BufRead::split
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* fix docs
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
* Update src/io/buf_read/mod.rs
Co-Authored-By: Stjepan Glavina <stjepang@gmail.com>
2019-10-14 15:49:54 +02:00
Yoshua Wuyts
5f52efe465
Merge pull request #324 from async-rs/stabilize-future-join
...
stabilize future::{join,try_join}
2019-10-14 15:31:55 +02:00
Yoshua Wuyts
a9950c5c9f
stabilize task::ready! ( #325 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-14 15:06:24 +02:00
Yoshua Wuyts
fe88da4e64
make all print macros unstable ( #322 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-14 14:48:12 +02:00
Yoshua Wuyts
9b0e02dbb7
Merge pull request #326 from async-rs/fused-stream
...
add stream::FusedStream as "unstable"
2019-10-14 14:22:41 +02:00
Yoshua Wuyts
d6aa1fb501
Add task::yield_now as "unstable" ( #300 )
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-14 13:58:26 +02:00
Yoshua Wuyts
3ac4575d94
add stream::FusedStream
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-14 02:21:27 +02:00
Yoshua Wuyts
05ba07daf8
stabilize future::{join,try_join}
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-14 01:52:10 +02:00
Yoshua Wuyts
454018ef42
Merge pull request #321 from async-rs/stream_merge
...
rename stream::join to Stream::merge
2019-10-14 01:46:42 +02:00
Yoshua Wuyts
04342c7b5d
docs
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 22:05:11 +02:00
Yoshua Wuyts
b601bcfcb8
polish
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 21:55:19 +02:00
Yoshua Wuyts
84a148ddae
rename stream::join to Stream::merge
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 21:48:53 +02:00
Wouter Geraedts
8df55dd015
Implemented PathBuf::set_file_name
2019-10-13 21:46:04 +02:00
Wouter Geraedts
54c94b717c
Implemented PathBuf::set_extension
2019-10-13 21:41:16 +02:00
Wouter Geraedts
cc417cc001
Implemented PathBuf::push
2019-10-13 21:38:47 +02:00
Wouter Geraedts
07f9e48579
Implemented PathBuf::pop
2019-10-13 21:29:35 +02:00
Wouter Geraedts
71125d5c3b
Implemented PathBuf::new
2019-10-13 21:19:23 +02:00
Wouter Geraedts
47ef222dab
Implemented PathBuf::into_os_string
2019-10-13 21:13:01 +02:00
Yoshua Wuyts
a2baa1d8e0
rename stream::join to stream::merge
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 21:12:05 +02:00
Wouter Geraedts
80eaa28552
Implemented PathBuf::into_boxed_path
2019-10-13 21:11:42 +02:00
Wouter Geraedts
1bd17f11f2
Implemented PathBuf::as_path
2019-10-13 21:04:47 +02:00
Wouter Geraedts
409a10a8b5
Implemented Path::with_file_name
2019-10-13 20:55:56 +02:00
Wouter Geraedts
3c24b1891b
Implemented Path::with_extension
2019-10-13 20:54:08 +02:00
Wouter Geraedts
a17b017e01
Implemented Path::to_string_lossy
2019-10-13 20:49:57 +02:00
Wouter Geraedts
ea43d7fd29
Implemented Path::to_str
2019-10-13 20:46:51 +02:00
Wouter Geraedts
df53a07fc5
Implemented Path::strip_prefix
2019-10-13 20:45:06 +02:00
Wouter Geraedts
942403c52c
Implemented Path::starts_with
2019-10-13 20:14:07 +02:00
Wouter Geraedts
d349333a43
Implemented Path::read_link
2019-10-13 20:12:57 +02:00
Wouter Geraedts
89f73d3eda
Implemented Path::read_dir
2019-10-13 19:57:46 +02:00
Yoshua Wuyts
fef2e32a3c
cargo fmt
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 19:54:44 +02:00
Yoshua Wuyts
467b64b6e7
doc fmt
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 19:54:44 +02:00
Yoshua Wuyts
296d0d9d31
add print macros
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 19:54:44 +02:00
Yoshua Wuyts
04479b13c3
add io::stdio
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 19:54:44 +02:00
Yoshua Wuyts
33da049717
Merge pull request #311 from async-rs/missing-write-methods
...
Add Write::write_fmt
2019-10-13 19:53:04 +02:00
Wouter Geraedts
141954d205
Implemented Path::parent
2019-10-13 19:38:33 +02:00
Wouter Geraedts
cc57db02a3
Implemented Path::join
2019-10-13 19:33:55 +02:00
Wouter Geraedts
0c03b92373
Implemented Path::iter
2019-10-13 19:31:17 +02:00
Wouter Geraedts
5d87006006
Implemented Path::is_relative
2019-10-13 19:16:52 +02:00
Wouter Geraedts
df9a01f534
Implemented Path::is_file
2019-10-13 19:15:15 +02:00
Wouter Geraedts
20f58ea1c1
Implemented Path::is_absolute
2019-10-13 19:10:16 +02:00
Wouter Geraedts
3a9597cd32
Implemented Path::has_root
2019-10-13 19:07:12 +02:00
Wouter Geraedts
28e936f6fe
Implemented Path::file_stem
2019-10-13 19:05:18 +02:00
Wouter Geraedts
a6e1abecfc
Implemented Path::file_name
2019-10-13 19:03:33 +02:00
Wouter Geraedts
a7eaae91ae
Implemented Path::extension
2019-10-13 19:00:34 +02:00
Wouter Geraedts
4070833482
Implemented Path::ends_with
2019-10-13 18:58:36 +02:00
Wouter Geraedts
5235cd58be
Implemented Path::display
2019-10-13 18:56:26 +02:00
Wouter Geraedts
759e357bea
Implemented Path::ancestors
2019-10-13 18:54:36 +02:00
Wouter Geraedts
a57ba7ece0
Implemented Path::into_path_buf
2019-10-13 18:49:57 +02:00
Wouter Geraedts
6c6106a292
Implemented Path::{metadata, symlink_metadata}
2019-10-13 14:17:33 +02:00
Wouter Geraedts
6bbfd039b1
Fixed various tests
2019-10-13 14:11:41 +02:00
Wouter Geraedts
e690b55b18
Implemented fs::metadata and Path::exists
2019-10-13 13:52:58 +02:00
Wouter Geraedts
930b81868d
Use std variants of Path and PathBuf internally
2019-10-13 13:46:02 +02:00
Wouter Geraedts
3bd6a9df6d
Implemented components
2019-10-13 13:39:12 +02:00
Yoshua Wuyts
28b0ebe83a
Merge pull request #315 from k-nasa/add_flush_to_into_inner
...
Add BufWriter::into_inner flush
2019-10-13 13:38:22 +02:00
Wouter Geraedts
e27b578c27
WIP init Path and PathBuf async stubs
2019-10-13 13:06:39 +02:00
k-nasa
9d9543c46b
refactor: Remove needless main fn
2019-10-13 16:33:02 +09:00
k-nasa
13ff627b09
$cargo fmt
2019-10-13 16:02:02 +09:00
k-nasa
ad156b1fce
feat: Add BufWriter::into_inner flush
2019-10-13 15:55:32 +09:00
Yoshua Wuyts
b62e4a1e48
update desc
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 02:39:14 +02:00
Yoshua Wuyts
a1cd76e244
cargo fmt
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 01:36:44 +02:00
Yoshua Wuyts
f3eba1fb48
comments
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 01:35:16 +02:00
Yoshua Wuyts
570dedd712
cleanup
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 01:31:51 +02:00
Yoshua Wuyts
58c3a06a14
init write_fmt
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-13 01:29:17 +02:00
Yoshua Wuyts
30b5ca5851
Merge pull request #296 from stjepang/cleanup-bufwriter
...
Cleanup BufWriter
2019-10-10 15:51:50 +02:00
Yoshua Wuyts
9c32133f77
Merge pull request #295 from stjepang/cleanup-tosocketaddrs
...
Cleanup ToSocketAddrs, add more net reexports
2019-10-09 22:39:35 +02:00
Stjepan Glavina
de01a5c5b7
Stabilize io::Cursor
2019-10-09 17:19:34 +02:00
Stjepan Glavina
c890de2c52
Fix failing doc example
2019-10-09 14:49:31 +02:00
Stjepan Glavina
da2335bd57
Cleanup BufWriter
2019-10-09 14:45:40 +02:00
Stjepan Glavina
cbd458b1db
Cleanup ToSocketAddrs, add more net reexports
2019-10-09 14:26:14 +02:00
Yoshua Wuyts
fc904a22cd
add task::blocking docs
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-09 13:03:38 +02:00
Yoshua Wuyts
9ab7b1ae6e
Merge pull request #251 from async-rs/blocking-unstable
...
add an unstable `task::blocking` function
2019-10-09 12:32:44 +02:00
Yoshua Wuyts
460b8af50b
Merge pull request #287 from k-nasa/optimizing_allocations
...
Optimizing allocations using Stream::size_hint
2019-10-08 17:18:51 +02:00
Yoshua Wuyts
c27623c0fd
cargo fmt
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-08 14:58:39 +02:00
Yoshua Wuyts
647aab819f
impl feedback
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-08 14:55:09 +02:00
Yoshua Wuyts
df15c04f28
spawn_blocking -> blocking
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-08 14:24:37 +02:00
k-nasa
1c798387bf
$cargo fmt
2019-10-08 10:50:30 +09:00
k-nasa
9cede7f1e3
refactor: optimizing allocations
2019-10-08 00:06:49 +09:00
Miloš Vučenović
c3e38150e4
Fix uds listener hanging on accept ( #272 )
...
* Fix uds listener hanging on accept
UDS listener was hanging because the accept method would return
`Poll::Pending` without registering the task to be awoken in the case
when underlying unix listener returns a WouldBlock that gets converted
to None. This is a hacky fix for this case.
Should fix #248
* Test simulating uds ping-pong server/client
This one should reproduce #248 bug to prevent further regressions.
* Code review fixes
2019-10-07 16:49:42 +02:00
Yoshua Wuyts
5f708f3c4f
Merge pull request #270 from k-nasa/fix_clippy_warn
...
Fix clippy warning
2019-10-07 15:43:20 +02:00
Yoshua Wuyts
46ffe6ab63
Merge pull request #278 from Michael-J-Ward/fix-readme
...
Fixes feature flag used in generating the docs in the README
2019-10-07 15:41:04 +02:00
Michael J Ward
75b6c60c67
Corrects a cfg feature declaration in task/mod.rs
2019-10-06 12:00:02 -05:00
bors[bot]
ddee47231a
Merge #282
...
282: init path submodule as unstable r=yoshuawuyts a=yoshuawuyts
Ref #183 .
Similar to #257 this adds the `path` submodule as unstable. Filling in all re-exports from std for module completion. From there the we can build out `Path` and `PathBuf` accordingly. Thanks!
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-06 13:10:35 +00:00
Yoshua Wuyts
5b05846fb0
init path submodule as unstable
...
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-10-06 13:42:55 +02:00
Fedor Sakharov
49d123c7f9
Fix review nits
2019-10-06 08:32:44 +03:00
Fedor Sakharov
2384df11ed
Apply suggestions from code review
...
Co-Authored-By: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
2019-10-06 08:27:44 +03:00
k-nasa
1c9d7895df
doc: Add FromStream document
2019-10-06 13:08:35 +09:00
Fedor Sakharov
735d604cd1
Adds stream::repeat_with
2019-10-05 22:17:21 +03:00
Sunjay Varma
f968c9a540
rustfmt
2019-10-04 10:09:06 -04:00
Sunjay Varma
2cf3f3f566
FromStream for Arc<[T]> and Rc<[T]>
2019-10-04 10:09:06 -04:00
Sunjay Varma
63c6b1cb63
impl FromStream for Box<[T]>
2019-10-04 10:09:06 -04:00
Sunjay Varma
8e12798038
impl FromStream for Cow<[T]>
2019-10-04 10:09:06 -04:00
Sunjay Varma
b2174576b2
Added FromStream + Extend for LinkedList
2019-10-04 10:09:06 -04:00
Sunjay Varma
bd0808eedd
Added FromStream + Extend for BinaryHeap
2019-10-04 10:09:06 -04:00
Sunjay Varma
3160dc8189
Added FromStream + Extend for BTreeSet
2019-10-04 10:09:06 -04:00
Sunjay Varma
6c2ffd7181
Added FromStream + Extend for HashSet
2019-10-04 10:09:06 -04:00
Sunjay Varma
333f35338e
Added FromStream and Extend impls for HashMap
2019-10-04 10:09:06 -04:00
Sunjay Varma
de2bc1e83b
Added FromStream + Extend for BTreeMap
2019-10-04 10:09:06 -04:00
Sunjay Varma
244c5159df
Simplifying + optimizing Extend impl for Vec
2019-10-04 10:09:06 -04:00
Sunjay Varma
ae146afffc
FromStream + Extend for VecDeque
2019-10-04 10:09:06 -04:00
Sunjay Varma
6bc3cd0ab2
FromStream for ()
2019-10-04 10:08:07 -04:00
bors[bot]
6ab154be7c
Merge #266
...
266: Changes Extend trait in order to allow streams that yield references r=yoshuawuyts a=sunjay
This is not ready to merge yet. I am mainly opening it so we can discuss a change I had to make to the `Extend` trait. cc @yoshuawuyts @stjepang (and anyone else interested)
## Before this can be merged
- [x] Discuss/Approve changes to `Extend` trait
- [x] Change to using `for_each` after #264 is merged
- [ ] (optional) Wait until a `copied()` method is added to `StreamExt` so that the `&char` impl can be finished.
- We can also just comment out or remove the impl that uses `copied` until that is added
## Changes To The Extend Trait
While writing the impls of the `Extend` trait for the `String` type, I noticed that certain impls weren't possible because there is no bound on `Extend` that guarantees that the type `A` being yielded from the stream actually lives long enough. We probably didn't run into this earlier because this usually isn't a problem for owned values since the compiler doesn't have to worry about whether they will out live the stream that they come from. I ran into this because of the `Extend` impls that consume streams of references.
The difference between the async `Extend` and the standard library `Extend` is that the async `Extend` returns a value that still references the input stream. That means that if `A` is any reference type, the compiler needs to be able to guarantee that `A` will be around as long as the `Future` returned from the trait method is around.
To fix this, I had to add the bound shown below:
```patch
pub trait Extend<A> {
/// Extends a collection with the contents of a stream.
fn stream_extend<'a, T: IntoStream<Item = A> + 'a>(
&'a mut self,
stream: T,
- ) -> Pin<Box<dyn Future<Output = ()> + 'a>>;
+ ) -> Pin<Box<dyn Future<Output = ()> + 'a>> where A: 'a;
}
```
This guarantees that each value of type `A` will last at least as long as our boxed future does. The bound had to be in a where clause on the method (and not on the declaration of `A` because the lifetime `'a` isn't in scope at the trait level. I don't think there are any negative consequences of using a where clause like this, but that's why I wanted to bring it up for discussion.
In addition to this, I had to ensure that when writing the `Extend` impls for `String` I appropriately bounded the lifetime of the references from the stream. You can see this in the code below with `where 'b: 'a`.
```rust
impl<'b> Extend<&'b str> for String {
fn stream_extend<'a, S: IntoStream<Item = &'b str> + 'a>(
&'a mut self,
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> where 'b: 'a {
//TODO: This can just be: stream.into_stream().for_each(move |s| self.push_str(s))
Box::pin(stream.into_stream().fold((), move |(), s| self.push_str(s)))
}
}
```
I should note that initially I tried to make it work with just the impl shown above, without modifying the `Extend` trait. This doesn't work because it would be a stricter bound than what is found in the trait itself. Rust does not allow stricter bounds like that because it could potentially cause unsoundness when dealing with generics.
Of course, I am totally open to being completely wrong in my understanding of how to resolve this issue. I tried to solve the problem with as minimal of a change as possible. Please let me know if you have some better ideas or other suggestions.
## `FromStream` impls for String
The purpose of adding these `Extend` impls is to continue my work from #129 in adding the rest of the `FromStream` impls. The `Extend` impls are used directly to add all of the `FromStream` impls for `String`. Just like with #207 and #265 , this adds a new `string` module that is unstable just like the other modules added for `FromStream`.
Co-authored-by: Sunjay Varma <varma.sunjay@gmail.com>
2019-10-04 13:55:33 +00:00
Yoshua Wuyts
5bd6acde46
Merge pull request #263 from montekki/fs-stream-map
...
Adds stream map combinator
2019-10-03 00:45:27 +02:00
Yoshua Wuyts
50b6d0b15f
Merge pull request #269 from montekki/fs-stream-try-for-each
...
Adds try_for_each combinator
2019-10-02 19:36:04 +02:00
Sunjay Varma
09a15ef116
Implementing Extend for String in terms of for_each now that that's been added
2019-10-01 22:39:57 -04:00