Commit Graph

547 Commits (f8af22ff98696059f1fc1984a89637479b63ae7b)
 

Author SHA1 Message Date
Taiki Endo f8af22ff98 Remove travis from requirements 5 years ago
Taiki Endo 5b9d34a34c Tweak job name 5 years ago
Taiki Endo d9d59dc710 Add GitHub Actions to the merge requirement of bors 5 years ago
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
5 years ago
Yoshua Wuyts 5f708f3c4f
Merge pull request #270 from k-nasa/fix_clippy_warn
Fix clippy warning
5 years ago
Yoshua Wuyts 46ffe6ab63
Merge pull request #278 from Michael-J-Ward/fix-readme
Fixes feature flag used in generating the docs in the README
5 years ago
Michael J Ward 75b6c60c67 Corrects a cfg feature declaration in task/mod.rs 5 years ago
Michael J Ward 0d521cb77c Removes unstable feature flag from CI doc commands
Per Stjepan Glavina, this flag is superfluous because #[cfg(any(feature = "unstable", feature = "docs"))]
is used everywhere in the codebase.

Discussion: https://github.com/async-rs/async-std/pull/278#issuecomment-538744737
5 years ago
Michael J Ward cf6277bcdc Adds +nightly to cargo commands in README 5 years ago
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>
5 years ago
Yoshua Wuyts 5b05846fb0
init path submodule as unstable
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
5 years ago
bors[bot] eb0494984f
Merge #281
281: Add FromStream documentation r=yoshuawuyts a=k-nasa

Ref: https://github.com/async-rs/async-std/issues/276


Co-authored-by: k-nasa <htilcs1115@gmail.com>
5 years ago
k-nasa 1c9d7895df doc: Add FromStream document 5 years ago
Yoshua Wuyts 51e7f880b1
Merge pull request #280 from async-rs/components-nightly
install rustfmt with fallback for gh-actions
5 years ago
Yoshua Wuyts b901c3d04a
install rustfmt with fallback for gh-actions
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
5 years ago
Michael J Ward 252bbddbd1 Fixes feature flag used in generating the docs in the README 5 years ago
bors[bot] 6fe958f745
Merge #271
271: FromStream impls for collections (and more!) r=yoshuawuyts a=sunjay

Just opening this to have some visibility on my work as I finish it off. Hopefully will be done in the next day or two, but if not, this is here for someone else to finish it off.

I'm currently in the process of adding the `FromStream` impls for all the collections. This is generally a very easy and repetitive process:

1. Look up the impl of `FromIterator` for the given collection, it probably uses the `Extend` trait which is also implemented for that collection
2. Copy and paste the directory for the collection that is closest to the collection you're currently doing (closest in terms of the type parameters needed)
3. Update the `Extend` impl to be for the collection you're implementing, being careful to use the `reserve` method if the collection has one to avoid allocating too many times
4. Update the `FromStream` impl to be for the collection you're implementing
5. Make sure you update the docs in the copied `mod.rs` and that you've updated `collections/mod.rs`
6. Test with `--features unstable` or your code will not be compiled

The majority of this work is just looking at what `std` does and adapting it to streams. Honestly it's kind of relaxing after a long day... (maybe I'm weird!) 😄

Co-authored-by: Sunjay Varma <varma.sunjay@gmail.com>
5 years ago
Sunjay Varma f968c9a540 rustfmt 5 years ago
Sunjay Varma 2cf3f3f566 FromStream for Arc<[T]> and Rc<[T]> 5 years ago
Sunjay Varma 63c6b1cb63 impl FromStream for Box<[T]> 5 years ago
Sunjay Varma 8e12798038 impl FromStream for Cow<[T]> 5 years ago
Sunjay Varma b2174576b2 Added FromStream + Extend for LinkedList 5 years ago
Sunjay Varma bd0808eedd Added FromStream + Extend for BinaryHeap 5 years ago
Sunjay Varma 3160dc8189 Added FromStream + Extend for BTreeSet 5 years ago
Sunjay Varma 6c2ffd7181 Added FromStream + Extend for HashSet 5 years ago
Sunjay Varma 333f35338e Added FromStream and Extend impls for HashMap 5 years ago
Sunjay Varma de2bc1e83b Added FromStream + Extend for BTreeMap 5 years ago
Sunjay Varma 244c5159df Simplifying + optimizing Extend impl for Vec 5 years ago
Sunjay Varma ae146afffc FromStream + Extend for VecDeque 5 years ago
Sunjay Varma 6bc3cd0ab2 FromStream for () 5 years ago
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>
5 years ago
Yoshua Wuyts 5bd6acde46
Merge pull request #263 from montekki/fs-stream-map
Adds stream map combinator
5 years ago
Yoshua Wuyts 6bae6b16f2
Merge pull request #267 from k-nasa/fix_github_actions
Add pull_request event to github actions hooks
5 years ago
Yoshua Wuyts 50b6d0b15f
Merge pull request #269 from montekki/fs-stream-try-for-each
Adds try_for_each combinator
5 years ago
Sunjay Varma 09a15ef116 Implementing Extend for String in terms of for_each now that that's been added 5 years ago
Sunjay Varma d6f16b6a17 rustfmt 5 years ago
Sunjay Varma b878855bc3 **CHANGES** extend trait in order to allow FromStream impls for String 5 years ago
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>
5 years ago
Taiki Endo 77ebedd44c Temporarily deactivate the surf example 5 years ago
Fedor Sakharov 35ab65fe8e
Fix docs 5 years ago
Fedor Sakharov f4e2302e7e
Don't use Try trait, use Result instead 5 years ago
k-nasa c947cf4043 fix github actions event 5 years ago
k-nasa 7ea3f4d0e2 fix github actions evnet 5 years ago
Yoshua Wuyts a97a1fffff
Merge pull request #264 from montekki/fs-stream-for-each
Adds for_each stream combinator
5 years ago
Yoshua Wuyts 0b57100e27
Merge pull request #265 from sunjay/fromstream-option-vec
FromStream impl for Option<T> + Revised impl for Vec<T>
5 years ago
k-nasa cc21bdf068 $cargo fmt 5 years ago
k-nasa c31861aa65 rafactor if expression 5 years ago
k-nasa f08fcd0bbb refactor 5 years ago
k-nasa 87b272f83d refacotr: Refactor match expression 5 years ago
k-nasa 2460f35768 fix: Remove unnecessary Borrowed
Each implements a Copy trait
5 years ago