2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-16 10:49:55 +00:00
Commit graph

521 commits

Author SHA1 Message Date
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
6bae6b16f2
Merge pull request #267 from k-nasa/fix_github_actions
Add pull_request event to github actions hooks
2019-10-02 20:41:01 +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
Sunjay Varma
d6f16b6a17 rustfmt 2019-10-01 22:31:29 -04:00
Sunjay Varma
b878855bc3 **CHANGES** extend trait in order to allow FromStream impls for String 2019-10-01 22:31:29 -04:00
bors[bot]
98c79f4ff9
Merge #255
255: Update futures-preview to 0.3.0-alpha.19 r=skade a=taiki-e

Depends on https://github.com/rustasync/surf/pull/74

Refs:
* https://github.com/rust-lang-nursery/futures-rs/issues/1761
* https://github.com/rust-lang-nursery/futures-rs/pull/1845


cc @skade @stjepang @yoshuawuyts 

Co-authored-by: Taiki Endo <te316e89@gmail.com>
2019-10-01 21:15:00 +00:00
Taiki Endo
77ebedd44c Temporarily deactivate the surf example 2019-10-02 02:23:41 +09:00
Fedor Sakharov
35ab65fe8e
Fix docs 2019-10-01 20:07:56 +03:00
Fedor Sakharov
f4e2302e7e
Don't use Try trait, use Result instead 2019-10-01 18:08:39 +03:00
k-nasa
c947cf4043 fix github actions event 2019-10-01 23:24:21 +09:00
k-nasa
7ea3f4d0e2 fix github actions evnet 2019-10-01 23:16:39 +09:00
Yoshua Wuyts
a97a1fffff
Merge pull request #264 from montekki/fs-stream-for-each
Adds for_each stream combinator
2019-10-01 15:32:36 +02:00
Yoshua Wuyts
0b57100e27
Merge pull request #265 from sunjay/fromstream-option-vec
FromStream impl for Option<T> + Revised impl for Vec<T>
2019-10-01 13:34:00 +02:00
Fedor Sakharov
66d38f7856
Adds try_for_each combinator 2019-10-01 10:39:43 +03:00
k-nasa
da9cbd99c4 Add hook pull_request event 2019-10-01 10:46:05 +09:00
Sunjay Varma
a05b564486 rustfmt 2019-09-30 20:14:16 -04:00
Sunjay Varma
fb7582bd7a Using Box::pin(...) instead of Pin::from(Box::new(...)) 2019-09-30 19:42:30 -04:00
Sunjay Varma
ab7129cd45 FromStream for Vec<T> in terms of Extend 2019-09-30 19:42:30 -04:00
Sunjay Varma
76b10c4784 FromStream for Option<T> 2019-09-30 19:42:30 -04:00
Fedor Sakharov
6da7efc5ac
Adds for_each stream combinator 2019-09-30 23:45:00 +03:00
Fedor Sakharov
658a16bebe
Adds stream map combinator 2019-09-30 23:17:25 +03:00
Florian Gilcher
33d2191cec
Merge pull request #253 from k-nasa/add_github_ci
Add github actions workflows
2019-09-30 14:42:06 +02:00
k-nasa
4bbc95b6a2 fix 2019-09-30 09:54:59 +09:00
bors[bot]
247afb450b
Merge #260
260: update Barrier example to match std::sync::Barrier 1:1 r=yoshuawuyts a=yoshuawuyts

This makes our impl's exmaple match [std's Barrier example](https://doc.rust-lang.org/std/sync/struct.Barrier.html) 1:1. Thanks!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-09-29 13:56:03 +00:00
nasa
3b213e95d7
Update .github/workflows/ci.yml
Co-Authored-By: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
2019-09-29 18:32:39 +09:00
Yoshua Wuyts
06862d47c3
update Barrier example to match std::sync::Barrier 1:1
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-09-29 04:21:48 +02:00
bors[bot]
5881d9adde
Merge #256
256: update changelog r=yoshuawuyts a=yoshuawuyts

Updates the changelog for 0.99.8. Thanks!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-09-29 00:48:46 +00:00
Yoshua Wuyts
000c98bf88
update changelog
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-09-28 17:58:08 +02:00
Taiki Endo
f0bf66d0df Update futures-preview to 0.3.0-alpha.19 2019-09-29 00:38:49 +09:00
Florian Gilcher
155256cfd6
Merge pull request #254 from async-rs/release-0.99.8
Release 0.99.8
2019-09-28 16:49:28 +02:00
Florian Gilcher
b2df0d37fb
Release 0.99.8 2019-09-28 16:32:11 +02:00
Florian Gilcher
47daf555f3
Pin futures to 0.3.0-alpha.18 2019-09-28 16:31:36 +02:00
k-nasa
f8de25168d Add github actions workflows 2019-09-28 21:49:16 +09:00
bors[bot]
b8b25b1781
Merge #252
252: prune deps r=yoshuawuyts a=yoshuawuyts

This makes `broadcaster` use `std::sync::Mutex` rather than `parking_lot`, saving on some deps. Thanks!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-09-28 11:04:57 +00:00
bors[bot]
383f7e9322
Merge #245
245: feat: missing Read and Write methods r=yoshuawuyts a=dignifiedquire

Ref: #131 

- [x] Read::by_ref
- [x] Read::bytes
- [x] Read::chain
- [x] Read::take
- [ ] Write::by_ref
- [ ] ~~Write::write_fmt~~ postponed until https://github.com/async-rs/async-std/issues/247 is solved

Needs fixing:

- [x] `BufRead` for `Take`
- [x] `BufRead` for `Chain`
- [ ] `by_ref` conflict between `Read` and `Write`, unable to add both, as they conflict, and the current state of things does not allow to differentiate between the two.


Co-authored-by: dignifiedquire <dignifiedquire@users.noreply.github.com>
2019-09-28 00:51:06 +00:00
dignifiedquire
064b44f695 apply cr 2019-09-27 18:49:23 -06:00
Yoshua Wuyts
4a09cbf577
prune deps
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2019-09-28 01:50:38 +02:00