Skip to content

Commit 1c2055f

Browse files
committed
Merge remote-tracking branch 'original/master' into future-timeout
2 parents c1f7be5 + bf9ee88 commit 1c2055f

33 files changed

+404
-93
lines changed

.github/CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Our contribution policy can be found at [async.rs/contribute][policy].
2+
3+
[policy]: https://async.rs/contribute/

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
push:
66
branches:
7+
- master
78
- staging
89
- trying
910

CHANGELOG.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,49 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
77

88
## [Unreleased]
99

10+
# [1.2.0] - 2019-11-27
11+
12+
[API Documentation](https://docs.rs/async-std/1.2.0/async-std)
13+
14+
This patch includes some minor quality-of-life improvements, introduces a
15+
new `Stream::unzip` API, and adds verbose errors to our networking types.
16+
17+
This means if you can't connect to a socket, you'll never have to wonder again
18+
*which* address it was you couldn't connect to, instead of having to go through
19+
the motions to debug what the address was.
20+
21+
## Example
22+
23+
Unzip a stream of tuples into two collections:
24+
25+
```rust
26+
use async_std::prelude::*;
27+
use async_std::stream;
28+
29+
let s = stream::from_iter(vec![(1,2), (3,4)]);
30+
31+
let (left, right): (Vec<_>, Vec<_>) = s.unzip().await;
32+
33+
assert_eq!(left, [1, 3]);
34+
assert_eq!(right, [2, 4]);
35+
```
36+
37+
## Added
38+
39+
- Added `Stream::unzip` as "unstable".
40+
- Added verbose errors to the networking types.
41+
42+
## Changed
43+
44+
- Enabled CI on master branch.
45+
- `Future::join` and `Future::try_join` can now join futures with different
46+
output types.
47+
48+
## Fixed
49+
50+
- Fixed the docs and `Debug` output of `BufWriter`.
51+
- Fixed a bug in `Stream::throttle` that made it consume too much CPU.
52+
1053
# [1.1.0] - 2019-11-21
1154

1255
[API Documentation](https://docs.rs/async-std/1.1.0/async-std)
@@ -510,7 +553,8 @@ task::blocking(async {
510553

511554
- Initial beta release
512555

513-
[Unreleased]: https://github.com/async-rs/async-std/compare/v1.1.0...HEAD
556+
[Unreleased]: https://github.com/async-rs/async-std/compare/v1.2.0...HEAD
557+
[1.2.0]: https://github.com/async-rs/async-std/compare/v1.1.0...v1.2.0
514558
[1.1.0]: https://github.com/async-rs/async-std/compare/v1.0.1...v1.1.0
515559
[1.0.1]: https://github.com/async-rs/async-std/compare/v1.0.0...v1.0.1
516560
[1.0.0]: https://github.com/async-rs/async-std/compare/v0.99.12...v1.0.0

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "async-std"
3-
version = "1.1.0"
3+
version = "1.2.0"
44
authors = [
55
"Stjepan Glavina <[email protected]>",
66
"Yoshua Wuyts <[email protected]>",

src/fs/canonicalize.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::{Path, PathBuf};
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Returns the canonical form of a path.
67
///
@@ -32,5 +33,10 @@ use crate::task::spawn_blocking;
3233
/// ```
3334
pub async fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
3435
let path = path.as_ref().to_owned();
35-
spawn_blocking(move || std::fs::canonicalize(&path).map(Into::into)).await
36+
spawn_blocking(move || {
37+
std::fs::canonicalize(&path)
38+
.map(Into::into)
39+
.context(|| format!("could not canonicalize `{}`", path.display()))
40+
})
41+
.await
3642
}

src/fs/copy.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Copies the contents and permissions of a file to a new location.
67
///
@@ -41,5 +42,9 @@ use crate::task::spawn_blocking;
4142
pub async fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
4243
let from = from.as_ref().to_owned();
4344
let to = to.as_ref().to_owned();
44-
spawn_blocking(move || std::fs::copy(&from, &to)).await
45+
spawn_blocking(move || {
46+
std::fs::copy(&from, &to)
47+
.context(|| format!("could not copy `{}` to `{}`", from.display(), to.display()))
48+
})
49+
.await
4550
}

src/fs/create_dir.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Creates a new directory.
67
///
@@ -34,5 +35,9 @@ use crate::task::spawn_blocking;
3435
/// ```
3536
pub async fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3637
let path = path.as_ref().to_owned();
37-
spawn_blocking(move || std::fs::create_dir(path)).await
38+
spawn_blocking(move || {
39+
std::fs::create_dir(&path)
40+
.context(|| format!("could not create directory `{}`", path.display()))
41+
})
42+
.await
3843
}

src/fs/create_dir_all.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Creates a new directory and all of its parents if they are missing.
67
///
@@ -29,5 +30,9 @@ use crate::task::spawn_blocking;
2930
/// ```
3031
pub async fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
3132
let path = path.as_ref().to_owned();
32-
spawn_blocking(move || std::fs::create_dir_all(path)).await
33+
spawn_blocking(move || {
34+
std::fs::create_dir_all(&path)
35+
.context(|| format!("could not create directory path `{}`", path.display()))
36+
})
37+
.await
3338
}

src/fs/file.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use std::sync::{Arc, Mutex};
99

1010
use crate::fs::{Metadata, Permissions};
1111
use crate::future;
12-
use crate::utils::Context as _;
1312
use crate::io::{self, Read, Seek, SeekFrom, Write};
1413
use crate::path::Path;
1514
use crate::prelude::*;
1615
use crate::task::{self, spawn_blocking, Context, Poll, Waker};
16+
use crate::utils::Context as _;
1717

1818
/// An open file on the filesystem.
1919
///
@@ -114,8 +114,7 @@ impl File {
114114
pub async fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
115115
let path = path.as_ref().to_owned();
116116
let file = spawn_blocking(move || {
117-
std::fs::File::open(&path)
118-
.context(|| format!("Could not open {}", path.display()))
117+
std::fs::File::open(&path).context(|| format!("could not open `{}`", path.display()))
119118
})
120119
.await?;
121120
Ok(File::new(file, true))
@@ -154,7 +153,7 @@ impl File {
154153
let path = path.as_ref().to_owned();
155154
let file = spawn_blocking(move || {
156155
std::fs::File::create(&path)
157-
.context(|| format!("Could not create {}", path.display()))
156+
.context(|| format!("could not create `{}`", path.display()))
158157
})
159158
.await?;
160159
Ok(File::new(file, true))

src/fs/hard_link.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Creates a hard link on the filesystem.
67
///
@@ -32,5 +33,14 @@ use crate::task::spawn_blocking;
3233
pub async fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
3334
let from = from.as_ref().to_owned();
3435
let to = to.as_ref().to_owned();
35-
spawn_blocking(move || std::fs::hard_link(&from, &to)).await
36+
spawn_blocking(move || {
37+
std::fs::hard_link(&from, &to).context(|| {
38+
format!(
39+
"could not create a hard link from `{}` to `{}`",
40+
from.display(),
41+
to.display()
42+
)
43+
})
44+
})
45+
.await
3646
}

src/fs/read.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Reads the entire contents of a file as raw bytes.
67
///
@@ -36,5 +37,8 @@ use crate::task::spawn_blocking;
3637
/// ```
3738
pub async fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
3839
let path = path.as_ref().to_owned();
39-
spawn_blocking(move || std::fs::read(path)).await
40+
spawn_blocking(move || {
41+
std::fs::read(&path).context(|| format!("could not read file `{}`", path.display()))
42+
})
43+
.await
4044
}

src/fs/read_dir.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use std::pin::Pin;
21
use std::future::Future;
2+
use std::pin::Pin;
33

44
use crate::fs::DirEntry;
55
use crate::io;
66
use crate::path::Path;
77
use crate::stream::Stream;
88
use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
9+
use crate::utils::Context as _;
910

1011
/// Returns a stream of entries in a directory.
1112
///
@@ -45,9 +46,12 @@ use crate::task::{spawn_blocking, Context, JoinHandle, Poll};
4546
/// ```
4647
pub async fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
4748
let path = path.as_ref().to_owned();
48-
spawn_blocking(move || std::fs::read_dir(path))
49-
.await
50-
.map(ReadDir::new)
49+
spawn_blocking(move || {
50+
std::fs::read_dir(&path)
51+
.context(|| format!("could not read directory `{}`", path.display()))
52+
})
53+
.await
54+
.map(ReadDir::new)
5155
}
5256

5357
/// A stream of entries in a directory.

src/fs/read_link.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::{Path, PathBuf};
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Reads a symbolic link and returns the path it points to.
67
///
@@ -28,5 +29,10 @@ use crate::task::spawn_blocking;
2829
/// ```
2930
pub async fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
3031
let path = path.as_ref().to_owned();
31-
spawn_blocking(move || std::fs::read_link(path).map(Into::into)).await
32+
spawn_blocking(move || {
33+
std::fs::read_link(&path)
34+
.map(Into::into)
35+
.context(|| format!("could not read link `{}`", path.display()))
36+
})
37+
.await
3238
}

src/fs/read_to_string.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Reads the entire contents of a file as a string.
67
///
@@ -37,5 +38,9 @@ use crate::task::spawn_blocking;
3738
/// ```
3839
pub async fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
3940
let path = path.as_ref().to_owned();
40-
spawn_blocking(move || std::fs::read_to_string(path)).await
41+
spawn_blocking(move || {
42+
std::fs::read_to_string(&path)
43+
.context(|| format!("could not read file `{}`", path.display()))
44+
})
45+
.await
4146
}

src/fs/remove_dir.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Removes an empty directory.
67
///
@@ -29,5 +30,9 @@ use crate::task::spawn_blocking;
2930
/// ```
3031
pub async fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3132
let path = path.as_ref().to_owned();
32-
spawn_blocking(move || std::fs::remove_dir(path)).await
33+
spawn_blocking(move || {
34+
std::fs::remove_dir(&path)
35+
.context(|| format!("could not remove directory `{}`", path.display()))
36+
})
37+
.await
3338
}

src/fs/remove_dir_all.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Removes a directory and all of its contents.
67
///
@@ -29,5 +30,9 @@ use crate::task::spawn_blocking;
2930
/// ```
3031
pub async fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
3132
let path = path.as_ref().to_owned();
32-
spawn_blocking(move || std::fs::remove_dir_all(path)).await
33+
spawn_blocking(move || {
34+
std::fs::remove_dir_all(&path)
35+
.context(|| format!("could not remove directory `{}`", path.display()))
36+
})
37+
.await
3338
}

src/fs/remove_file.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Removes a file.
67
///
@@ -29,5 +30,9 @@ use crate::task::spawn_blocking;
2930
/// ```
3031
pub async fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
3132
let path = path.as_ref().to_owned();
32-
spawn_blocking(move || std::fs::remove_file(path)).await
33+
spawn_blocking(move || {
34+
std::fs::remove_file(&path)
35+
.context(|| format!("could not remove file `{}`", path.display()))
36+
})
37+
.await
3338
}

src/fs/rename.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Renames a file or directory to a new location.
67
///
@@ -34,5 +35,14 @@ use crate::task::spawn_blocking;
3435
pub async fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
3536
let from = from.as_ref().to_owned();
3637
let to = to.as_ref().to_owned();
37-
spawn_blocking(move || std::fs::rename(&from, &to)).await
38+
spawn_blocking(move || {
39+
std::fs::rename(&from, &to).context(|| {
40+
format!(
41+
"could not rename `{}` to `{}`",
42+
from.display(),
43+
to.display()
44+
)
45+
})
46+
})
47+
.await
3848
}

src/fs/write.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::io;
22
use crate::path::Path;
33
use crate::task::spawn_blocking;
4+
use crate::utils::Context as _;
45

56
/// Writes a slice of bytes as the new contents of a file.
67
///
@@ -33,5 +34,9 @@ use crate::task::spawn_blocking;
3334
pub async fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
3435
let path = path.as_ref().to_owned();
3536
let contents = contents.as_ref().to_owned();
36-
spawn_blocking(move || std::fs::write(path, contents)).await
37+
spawn_blocking(move || {
38+
std::fs::write(&path, contents)
39+
.context(|| format!("could not write to file `{}`", path.display()))
40+
})
41+
.await
3742
}

0 commit comments

Comments
 (0)