Skip to content

Commit 5ed99d1

Browse files
committed
task::blocking async closure -> FnOnce
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent fa2ef82 commit 5ed99d1

31 files changed

+45
-47
lines changed

src/fs/canonicalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ use crate::task::blocking;
3333
/// ```
3434
pub async fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
3535
let path = path.as_ref().to_owned();
36-
blocking::spawn(async move { std::fs::canonicalize(path) }).await
36+
blocking::spawn(move || std::fs::canonicalize(path)).await
3737
}

src/fs/copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ use crate::task::blocking;
4242
pub async fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
4343
let from = from.as_ref().to_owned();
4444
let to = to.as_ref().to_owned();
45-
blocking::spawn(async move { std::fs::copy(&from, &to) }).await
45+
blocking::spawn(move || std::fs::copy(&from, &to)).await
4646
}

src/fs/create_dir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ use crate::task::blocking;
3535
/// ```
3636
pub async fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3737
let path = path.as_ref().to_owned();
38-
blocking::spawn(async move { std::fs::create_dir(path) }).await
38+
blocking::spawn(move || std::fs::create_dir(path)).await
3939
}

src/fs/create_dir_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ use crate::task::blocking;
3030
/// ```
3131
pub async fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
3232
let path = path.as_ref().to_owned();
33-
blocking::spawn(async move { std::fs::create_dir_all(path) }).await
33+
blocking::spawn(move || std::fs::create_dir_all(path)).await
3434
}

src/fs/dir_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl DirBuilder {
109109
}
110110

111111
let path = path.as_ref().to_owned();
112-
async move { blocking::spawn(async move { builder.create(path) }).await }
112+
async move { blocking::spawn(move || builder.create(path)).await }
113113
}
114114
}
115115

src/fs/dir_entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl DirEntry {
8989
/// ```
9090
pub async fn metadata(&self) -> io::Result<Metadata> {
9191
let inner = self.0.clone();
92-
blocking::spawn(async move { inner.metadata() }).await
92+
blocking::spawn(move || inner.metadata()).await
9393
}
9494

9595
/// Reads the file type for this entry.
@@ -127,7 +127,7 @@ impl DirEntry {
127127
/// ```
128128
pub async fn file_type(&self) -> io::Result<FileType> {
129129
let inner = self.0.clone();
130-
blocking::spawn(async move { inner.file_type() }).await
130+
blocking::spawn(move || inner.file_type()).await
131131
}
132132

133133
/// Returns the bare name of this entry without the leading path.

src/fs/file.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl File {
9797
/// ```
9898
pub async fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
9999
let path = path.as_ref().to_owned();
100-
let file = blocking::spawn(async move { std::fs::File::open(&path) }).await?;
100+
let file = blocking::spawn(move || std::fs::File::open(&path)).await?;
101101
Ok(file.into())
102102
}
103103

@@ -132,7 +132,7 @@ impl File {
132132
/// ```
133133
pub async fn create<P: AsRef<Path>>(path: P) -> io::Result<File> {
134134
let path = path.as_ref().to_owned();
135-
let file = blocking::spawn(async move { std::fs::File::create(&path) }).await?;
135+
let file = blocking::spawn(move || std::fs::File::create(&path)).await?;
136136
Ok(file.into())
137137
}
138138

@@ -165,7 +165,7 @@ impl File {
165165
})
166166
.await?;
167167

168-
blocking::spawn(async move { state.file.sync_all() }).await
168+
blocking::spawn(move || state.file.sync_all()).await
169169
}
170170

171171
/// Synchronizes OS-internal buffered contents to disk.
@@ -201,7 +201,7 @@ impl File {
201201
})
202202
.await?;
203203

204-
blocking::spawn(async move { state.file.sync_data() }).await
204+
blocking::spawn(move || state.file.sync_data()).await
205205
}
206206

207207
/// Truncates or extends the file.
@@ -234,7 +234,7 @@ impl File {
234234
})
235235
.await?;
236236

237-
blocking::spawn(async move { state.file.set_len(size) }).await
237+
blocking::spawn(move || state.file.set_len(size)).await
238238
}
239239

240240
/// Reads the file's metadata.
@@ -253,7 +253,7 @@ impl File {
253253
/// ```
254254
pub async fn metadata(&self) -> io::Result<Metadata> {
255255
let file = self.file.clone();
256-
blocking::spawn(async move { file.metadata() }).await
256+
blocking::spawn(move || file.metadata()).await
257257
}
258258

259259
/// Changes the permissions on the file.
@@ -282,7 +282,7 @@ impl File {
282282
/// ```
283283
pub async fn set_permissions(&self, perm: Permissions) -> io::Result<()> {
284284
let file = self.file.clone();
285-
blocking::spawn(async move { file.set_permissions(perm) }).await
285+
blocking::spawn(move || file.set_permissions(perm)).await
286286
}
287287
}
288288

@@ -702,7 +702,7 @@ impl LockGuard<State> {
702702
self.register(cx);
703703

704704
// Start a read operation asynchronously.
705-
blocking::spawn(async move {
705+
blocking::spawn(move || {
706706
// Read some data from the file into the cache.
707707
let res = {
708708
let State { file, cache, .. } = &mut *self;
@@ -811,7 +811,7 @@ impl LockGuard<State> {
811811
self.register(cx);
812812

813813
// Start a write operation asynchronously.
814-
blocking::spawn(async move {
814+
blocking::spawn(move || {
815815
match (&*self.file).write_all(&self.cache) {
816816
Ok(_) => {
817817
// Switch to idle mode.
@@ -844,7 +844,7 @@ impl LockGuard<State> {
844844
self.register(cx);
845845

846846
// Start a flush operation asynchronously.
847-
blocking::spawn(async move {
847+
blocking::spawn(move || {
848848
match (&*self.file).flush() {
849849
Ok(()) => {
850850
// Mark the file as flushed.

src/fs/hard_link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ use crate::task::blocking;
3333
pub async fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
3434
let from = from.as_ref().to_owned();
3535
let to = to.as_ref().to_owned();
36-
blocking::spawn(async move { std::fs::hard_link(&from, &to) }).await
36+
blocking::spawn(move || std::fs::hard_link(&from, &to)).await
3737
}

src/fs/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::task::blocking;
3737
/// ```
3838
pub async fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
3939
let path = path.as_ref().to_owned();
40-
blocking::spawn(async move { std::fs::metadata(path) }).await
40+
blocking::spawn(move || std::fs::metadata(path)).await
4141
}
4242

4343
cfg_if! {

src/fs/open_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl OpenOptions {
286286
pub fn open<P: AsRef<Path>>(&self, path: P) -> impl Future<Output = io::Result<File>> {
287287
let path = path.as_ref().to_owned();
288288
let options = self.0.clone();
289-
async move { blocking::spawn(async move { options.open(path).map(|f| f.into()) }).await }
289+
async move { blocking::spawn(move || options.open(path).map(|f| f.into())).await }
290290
}
291291
}
292292

src/fs/read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ use crate::task::blocking;
3737
/// ```
3838
pub async fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
3939
let path = path.as_ref().to_owned();
40-
blocking::spawn(async move { std::fs::read(path) }).await
40+
blocking::spawn(move || std::fs::read(path)).await
4141
}

src/fs/read_dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll};
4545
/// ```
4646
pub async fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
4747
let path = path.as_ref().to_owned();
48-
blocking::spawn(async move { std::fs::read_dir(path) })
48+
blocking::spawn(move || std::fs::read_dir(path))
4949
.await
5050
.map(ReadDir::new)
5151
}
@@ -91,7 +91,7 @@ impl Stream for ReadDir {
9191
let mut inner = opt.take().unwrap();
9292

9393
// Start the operation asynchronously.
94-
self.0 = State::Busy(blocking::spawn(async move {
94+
self.0 = State::Busy(blocking::spawn(move || {
9595
let next = inner.next();
9696
(inner, next)
9797
}));

src/fs/read_link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ use crate::task::blocking;
2929
/// ```
3030
pub async fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
3131
let path = path.as_ref().to_owned();
32-
blocking::spawn(async move { std::fs::read_link(path) }).await
32+
blocking::spawn(move || std::fs::read_link(path)).await
3333
}

src/fs/read_to_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ use crate::task::blocking;
3838
/// ```
3939
pub async fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
4040
let path = path.as_ref().to_owned();
41-
blocking::spawn(async move { std::fs::read_to_string(path) }).await
41+
blocking::spawn(move || std::fs::read_to_string(path)).await
4242
}

src/fs/remove_dir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ use crate::task::blocking;
3030
/// ```
3131
pub async fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3232
let path = path.as_ref().to_owned();
33-
blocking::spawn(async move { std::fs::remove_dir(path) }).await
33+
blocking::spawn(move || std::fs::remove_dir(path)).await
3434
}

src/fs/remove_dir_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ use crate::task::blocking;
3030
/// ```
3131
pub async fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
3232
let path = path.as_ref().to_owned();
33-
blocking::spawn(async move { std::fs::remove_dir_all(path) }).await
33+
blocking::spawn(move || std::fs::remove_dir_all(path)).await
3434
}

src/fs/remove_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ use crate::task::blocking;
3030
/// ```
3131
pub async fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
3232
let path = path.as_ref().to_owned();
33-
blocking::spawn(async move { std::fs::remove_file(path) }).await
33+
blocking::spawn(move || std::fs::remove_file(path)).await
3434
}

src/fs/rename.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ use crate::task::blocking;
3535
pub async fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
3636
let from = from.as_ref().to_owned();
3737
let to = to.as_ref().to_owned();
38-
blocking::spawn(async move { std::fs::rename(&from, &to) }).await
38+
blocking::spawn(move || std::fs::rename(&from, &to)).await
3939
}

src/fs/set_permissions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ use crate::task::blocking;
3333
/// ```
3434
pub async fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result<()> {
3535
let path = path.as_ref().to_owned();
36-
blocking::spawn(async move { std::fs::set_permissions(path, perm) }).await
36+
blocking::spawn(move || std::fs::set_permissions(path, perm)).await
3737
}

src/fs/symlink_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ use crate::task::blocking;
3535
/// ```
3636
pub async fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
3737
let path = path.as_ref().to_owned();
38-
blocking::spawn(async move { std::fs::symlink_metadata(path) }).await
38+
blocking::spawn(move || std::fs::symlink_metadata(path)).await
3939
}

src/fs/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ use crate::task::blocking;
3434
pub async fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
3535
let path = path.as_ref().to_owned();
3636
let contents = contents.as_ref().to_owned();
37-
blocking::spawn(async move { std::fs::write(path, contents) }).await
37+
blocking::spawn(move || std::fs::write(path, contents)).await
3838
}

src/io/stderr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Write for Stderr {
116116
inner.buf[..buf.len()].copy_from_slice(buf);
117117

118118
// Start the operation asynchronously.
119-
*state = State::Busy(blocking::spawn(async move {
119+
*state = State::Busy(blocking::spawn(move || {
120120
let res = std::io::Write::write(&mut inner.stderr, &inner.buf);
121121
inner.last_op = Some(Operation::Write(res));
122122
State::Idle(Some(inner))
@@ -144,7 +144,7 @@ impl Write for Stderr {
144144
let mut inner = opt.take().unwrap();
145145

146146
// Start the operation asynchronously.
147-
*state = State::Busy(blocking::spawn(async move {
147+
*state = State::Busy(blocking::spawn(move || {
148148
let res = std::io::Write::flush(&mut inner.stderr);
149149
inner.last_op = Some(Operation::Flush(res));
150150
State::Idle(Some(inner))

src/io/stdin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Stdin {
119119
let mut inner = opt.take().unwrap();
120120

121121
// Start the operation asynchronously.
122-
*state = State::Busy(blocking::spawn(async move {
122+
*state = State::Busy(blocking::spawn(move || {
123123
inner.line.clear();
124124
let res = inner.stdin.read_line(&mut inner.line);
125125
inner.last_op = Some(Operation::ReadLine(res));
@@ -172,7 +172,7 @@ impl Read for Stdin {
172172
}
173173

174174
// Start the operation asynchronously.
175-
*state = State::Busy(blocking::spawn(async move {
175+
*state = State::Busy(blocking::spawn(move || {
176176
let res = std::io::Read::read(&mut inner.stdin, &mut inner.buf);
177177
inner.last_op = Some(Operation::Read(res));
178178
State::Idle(Some(inner))

src/io/stdout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Write for Stdout {
116116
inner.buf[..buf.len()].copy_from_slice(buf);
117117

118118
// Start the operation asynchronously.
119-
*state = State::Busy(blocking::spawn(async move {
119+
*state = State::Busy(blocking::spawn(move || {
120120
let res = std::io::Write::write(&mut inner.stdout, &inner.buf);
121121
inner.last_op = Some(Operation::Write(res));
122122
State::Idle(Some(inner))
@@ -144,7 +144,7 @@ impl Write for Stdout {
144144
let mut inner = opt.take().unwrap();
145145

146146
// Start the operation asynchronously.
147-
*state = State::Busy(blocking::spawn(async move {
147+
*state = State::Busy(blocking::spawn(move || {
148148
let res = std::io::Write::flush(&mut inner.stdout);
149149
inner.last_op = Some(Operation::Flush(res));
150150
State::Idle(Some(inner))

src/net/addr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl ToSocketAddrs for (&str, u16) {
120120
fn to_socket_addrs(&self) -> ret!('_, ToSocketAddrsFuture, Self::Iter) {
121121
let host = self.0.to_string();
122122
let port = self.1;
123-
let join = blocking::spawn(async move {
123+
let join = blocking::spawn(move || {
124124
std::net::ToSocketAddrs::to_socket_addrs(&(host.as_str(), port))
125125
});
126126
ToSocketAddrsFuture::Join(join)
@@ -132,8 +132,7 @@ impl ToSocketAddrs for str {
132132

133133
fn to_socket_addrs(&self) -> ret!('_, ToSocketAddrsFuture, Self::Iter) {
134134
let socket_addrs = self.to_string();
135-
let join =
136-
blocking::spawn(async move { std::net::ToSocketAddrs::to_socket_addrs(&socket_addrs) });
135+
let join = blocking::spawn(move || std::net::ToSocketAddrs::to_socket_addrs(&socket_addrs));
137136
ToSocketAddrsFuture::Join(join)
138137
}
139138
}

src/net/tcp/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl TcpStream {
7676
let mut last_err = None;
7777

7878
for addr in addrs.to_socket_addrs().await? {
79-
let res = blocking::spawn(async move {
79+
let res = blocking::spawn(move || {
8080
let std_stream = std::net::TcpStream::connect(addr)?;
8181
let mio_stream = mio::net::TcpStream::from_stream(std_stream)?;
8282
Ok(TcpStream {

src/os/unix/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::task::blocking;
2929
pub async fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
3030
let src = src.as_ref().to_owned();
3131
let dst = dst.as_ref().to_owned();
32-
blocking::spawn(async move { std::os::unix::fs::symlink(&src, &dst) }).await
32+
blocking::spawn(move || std::os::unix::fs::symlink(&src, &dst)).await
3333
}
3434

3535
cfg_if! {

src/os/unix/net/datagram.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl UnixDatagram {
6767
/// ```
6868
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixDatagram> {
6969
let path = path.as_ref().to_owned();
70-
let socket = blocking::spawn(async move { mio_uds::UnixDatagram::bind(path) }).await?;
70+
let socket = blocking::spawn(move || mio_uds::UnixDatagram::bind(path)).await?;
7171
Ok(UnixDatagram::new(socket))
7272
}
7373

src/os/unix/net/listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl UnixListener {
6868
/// ```
6969
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
7070
let path = path.as_ref().to_owned();
71-
let listener = blocking::spawn(async move { mio_uds::UnixListener::bind(path) }).await?;
71+
let listener = blocking::spawn(move || mio_uds::UnixListener::bind(path)).await?;
7272

7373
Ok(UnixListener {
7474
watcher: Watcher::new(listener),

src/os/unix/net/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl UnixStream {
5858
pub async fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
5959
let path = path.as_ref().to_owned();
6060

61-
blocking::spawn(async move {
61+
blocking::spawn(move || {
6262
let std_stream = std::os::unix::net::UnixStream::connect(path)?;
6363
let mio_stream = mio_uds::UnixStream::from_stream(std_stream)?;
6464
Ok(UnixStream {

src/task/blocking.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::time::Duration;
77
use crossbeam_channel::{bounded, Receiver, Sender};
88
use lazy_static::lazy_static;
99

10-
use crate::future::Future;
1110
use crate::task::task::{JoinHandle, Tag};
1211
use crate::utils::abort_on_panic;
1312

0 commit comments

Comments
 (0)