diff --git a/src/fs/canonicalize.rs b/src/fs/canonicalize.rs index a763e4e..601d477 100644 --- a/src/fs/canonicalize.rs +++ b/src/fs/canonicalize.rs @@ -32,5 +32,5 @@ use crate::task::blocking; /// ``` pub async fn canonicalize>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::canonicalize(&path).map(Into::into) }).await + blocking::spawn(move || std::fs::canonicalize(&path).map(Into::into)).await } diff --git a/src/fs/copy.rs b/src/fs/copy.rs index c0c6b9e..733fb64 100644 --- a/src/fs/copy.rs +++ b/src/fs/copy.rs @@ -41,5 +41,5 @@ use crate::task::blocking; pub async fn copy, Q: AsRef>(from: P, to: Q) -> io::Result { let from = from.as_ref().to_owned(); let to = to.as_ref().to_owned(); - blocking::spawn(async move { std::fs::copy(&from, &to) }).await + blocking::spawn(move || std::fs::copy(&from, &to)).await } diff --git a/src/fs/create_dir.rs b/src/fs/create_dir.rs index 99f4ac4..740d303 100644 --- a/src/fs/create_dir.rs +++ b/src/fs/create_dir.rs @@ -34,5 +34,5 @@ use crate::task::blocking; /// ``` pub async fn create_dir>(path: P) -> io::Result<()> { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::create_dir(path) }).await + blocking::spawn(move || std::fs::create_dir(path)).await } diff --git a/src/fs/create_dir_all.rs b/src/fs/create_dir_all.rs index 0dc446e..76604de 100644 --- a/src/fs/create_dir_all.rs +++ b/src/fs/create_dir_all.rs @@ -29,5 +29,5 @@ use crate::task::blocking; /// ``` pub async fn create_dir_all>(path: P) -> io::Result<()> { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::create_dir_all(path) }).await + blocking::spawn(move || std::fs::create_dir_all(path)).await } diff --git a/src/fs/dir_builder.rs b/src/fs/dir_builder.rs index 1fb0850..738ddbc 100644 --- a/src/fs/dir_builder.rs +++ b/src/fs/dir_builder.rs @@ -108,7 +108,7 @@ impl DirBuilder { } let path = path.as_ref().to_owned(); - async move { blocking::spawn(async move { builder.create(path) }).await } + async move { blocking::spawn(move || builder.create(path)).await } } } diff --git a/src/fs/dir_entry.rs b/src/fs/dir_entry.rs index 3d42f83..80d4bbd 100644 --- a/src/fs/dir_entry.rs +++ b/src/fs/dir_entry.rs @@ -89,7 +89,7 @@ impl DirEntry { /// ``` pub async fn metadata(&self) -> io::Result { let inner = self.0.clone(); - blocking::spawn(async move { inner.metadata() }).await + blocking::spawn(move || inner.metadata()).await } /// Reads the file type for this entry. @@ -127,7 +127,7 @@ impl DirEntry { /// ``` pub async fn file_type(&self) -> io::Result { let inner = self.0.clone(); - blocking::spawn(async move { inner.file_type() }).await + blocking::spawn(move || inner.file_type()).await } /// Returns the bare name of this entry without the leading path. diff --git a/src/fs/file.rs b/src/fs/file.rs index b52bcd0..3916234 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -97,7 +97,7 @@ impl File { /// ``` pub async fn open>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - let file = blocking::spawn(async move { std::fs::File::open(&path) }).await?; + let file = blocking::spawn(move || std::fs::File::open(&path)).await?; Ok(file.into()) } @@ -132,7 +132,7 @@ impl File { /// ``` pub async fn create>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - let file = blocking::spawn(async move { std::fs::File::create(&path) }).await?; + let file = blocking::spawn(move || std::fs::File::create(&path)).await?; Ok(file.into()) } @@ -165,7 +165,7 @@ impl File { }) .await?; - blocking::spawn(async move { state.file.sync_all() }).await + blocking::spawn(move || state.file.sync_all()).await } /// Synchronizes OS-internal buffered contents to disk. @@ -201,7 +201,7 @@ impl File { }) .await?; - blocking::spawn(async move { state.file.sync_data() }).await + blocking::spawn(move || state.file.sync_data()).await } /// Truncates or extends the file. @@ -234,7 +234,7 @@ impl File { }) .await?; - blocking::spawn(async move { state.file.set_len(size) }).await + blocking::spawn(move || state.file.set_len(size)).await } /// Reads the file's metadata. @@ -253,7 +253,7 @@ impl File { /// ``` pub async fn metadata(&self) -> io::Result { let file = self.file.clone(); - blocking::spawn(async move { file.metadata() }).await + blocking::spawn(move || file.metadata()).await } /// Changes the permissions on the file. @@ -282,7 +282,7 @@ impl File { /// ``` pub async fn set_permissions(&self, perm: Permissions) -> io::Result<()> { let file = self.file.clone(); - blocking::spawn(async move { file.set_permissions(perm) }).await + blocking::spawn(move || file.set_permissions(perm)).await } } @@ -702,7 +702,7 @@ impl LockGuard { self.register(cx); // Start a read operation asynchronously. - blocking::spawn(async move { + blocking::spawn(move || { // Read some data from the file into the cache. let res = { let State { file, cache, .. } = &mut *self; @@ -811,7 +811,7 @@ impl LockGuard { self.register(cx); // Start a write operation asynchronously. - blocking::spawn(async move { + blocking::spawn(move || { match (&*self.file).write_all(&self.cache) { Ok(_) => { // Switch to idle mode. @@ -844,7 +844,7 @@ impl LockGuard { self.register(cx); // Start a flush operation asynchronously. - blocking::spawn(async move { + blocking::spawn(move || { match (&*self.file).flush() { Ok(()) => { // Mark the file as flushed. diff --git a/src/fs/hard_link.rs b/src/fs/hard_link.rs index 2ae2cad..8b09b5d 100644 --- a/src/fs/hard_link.rs +++ b/src/fs/hard_link.rs @@ -32,5 +32,5 @@ use crate::task::blocking; pub async fn hard_link, Q: AsRef>(from: P, to: Q) -> io::Result<()> { let from = from.as_ref().to_owned(); let to = to.as_ref().to_owned(); - blocking::spawn(async move { std::fs::hard_link(&from, &to) }).await + blocking::spawn(move || std::fs::hard_link(&from, &to)).await } diff --git a/src/fs/metadata.rs b/src/fs/metadata.rs index 8c92381..65f494b 100644 --- a/src/fs/metadata.rs +++ b/src/fs/metadata.rs @@ -36,7 +36,7 @@ use crate::task::blocking; /// ``` pub async fn metadata>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::metadata(path) }).await + blocking::spawn(move || std::fs::metadata(path)).await } cfg_if! { diff --git a/src/fs/open_options.rs b/src/fs/open_options.rs index d7e0454..a9511f1 100644 --- a/src/fs/open_options.rs +++ b/src/fs/open_options.rs @@ -285,7 +285,7 @@ impl OpenOptions { pub fn open>(&self, path: P) -> impl Future> { let path = path.as_ref().to_owned(); let options = self.0.clone(); - async move { blocking::spawn(async move { options.open(path).map(|f| f.into()) }).await } + async move { blocking::spawn(move || options.open(path).map(|f| f.into())).await } } } diff --git a/src/fs/read.rs b/src/fs/read.rs index b562ea3..a0eb130 100644 --- a/src/fs/read.rs +++ b/src/fs/read.rs @@ -36,5 +36,5 @@ use crate::task::blocking; /// ``` pub async fn read>(path: P) -> io::Result> { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::read(path) }).await + blocking::spawn(move || std::fs::read(path)).await } diff --git a/src/fs/read_dir.rs b/src/fs/read_dir.rs index fd1a21f..6e47801 100644 --- a/src/fs/read_dir.rs +++ b/src/fs/read_dir.rs @@ -45,7 +45,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll}; /// ``` pub async fn read_dir>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::read_dir(path) }) + blocking::spawn(move || std::fs::read_dir(path)) .await .map(ReadDir::new) } @@ -91,7 +91,7 @@ impl Stream for ReadDir { let mut inner = opt.take().unwrap(); // Start the operation asynchronously. - self.0 = State::Busy(blocking::spawn(async move { + self.0 = State::Busy(blocking::spawn(move || { let next = inner.next(); (inner, next) })); diff --git a/src/fs/read_link.rs b/src/fs/read_link.rs index 53080dd..eaa7b62 100644 --- a/src/fs/read_link.rs +++ b/src/fs/read_link.rs @@ -28,5 +28,5 @@ use crate::task::blocking; /// ``` pub async fn read_link>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::read_link(path).map(Into::into) }).await + blocking::spawn(move || std::fs::read_link(path).map(Into::into)).await } diff --git a/src/fs/read_to_string.rs b/src/fs/read_to_string.rs index a4d175f..40c4b6b 100644 --- a/src/fs/read_to_string.rs +++ b/src/fs/read_to_string.rs @@ -37,5 +37,5 @@ use crate::task::blocking; /// ``` pub async fn read_to_string>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::read_to_string(path) }).await + blocking::spawn(move || std::fs::read_to_string(path)).await } diff --git a/src/fs/remove_dir.rs b/src/fs/remove_dir.rs index f457124..d1fa7bf 100644 --- a/src/fs/remove_dir.rs +++ b/src/fs/remove_dir.rs @@ -29,5 +29,5 @@ use crate::task::blocking; /// ``` pub async fn remove_dir>(path: P) -> io::Result<()> { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::remove_dir(path) }).await + blocking::spawn(move || std::fs::remove_dir(path)).await } diff --git a/src/fs/remove_dir_all.rs b/src/fs/remove_dir_all.rs index 3b12d26..0a0fceb 100644 --- a/src/fs/remove_dir_all.rs +++ b/src/fs/remove_dir_all.rs @@ -29,5 +29,5 @@ use crate::task::blocking; /// ``` pub async fn remove_dir_all>(path: P) -> io::Result<()> { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::remove_dir_all(path) }).await + blocking::spawn(move || std::fs::remove_dir_all(path)).await } diff --git a/src/fs/remove_file.rs b/src/fs/remove_file.rs index 216209f..5bc0608 100644 --- a/src/fs/remove_file.rs +++ b/src/fs/remove_file.rs @@ -29,5 +29,5 @@ use crate::task::blocking; /// ``` pub async fn remove_file>(path: P) -> io::Result<()> { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::remove_file(path) }).await + blocking::spawn(move || std::fs::remove_file(path)).await } diff --git a/src/fs/rename.rs b/src/fs/rename.rs index f517a26..c2aa77b 100644 --- a/src/fs/rename.rs +++ b/src/fs/rename.rs @@ -34,5 +34,5 @@ use crate::task::blocking; pub async fn rename, Q: AsRef>(from: P, to: Q) -> io::Result<()> { let from = from.as_ref().to_owned(); let to = to.as_ref().to_owned(); - blocking::spawn(async move { std::fs::rename(&from, &to) }).await + blocking::spawn(move || std::fs::rename(&from, &to)).await } diff --git a/src/fs/set_permissions.rs b/src/fs/set_permissions.rs index 68dd8d4..d14ced9 100644 --- a/src/fs/set_permissions.rs +++ b/src/fs/set_permissions.rs @@ -32,5 +32,5 @@ use crate::task::blocking; /// ``` pub async fn set_permissions>(path: P, perm: Permissions) -> io::Result<()> { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::set_permissions(path, perm) }).await + blocking::spawn(move || std::fs::set_permissions(path, perm)).await } diff --git a/src/fs/symlink_metadata.rs b/src/fs/symlink_metadata.rs index e2bc12d..bc5cce8 100644 --- a/src/fs/symlink_metadata.rs +++ b/src/fs/symlink_metadata.rs @@ -34,5 +34,5 @@ use crate::task::blocking; /// ``` pub async fn symlink_metadata>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::symlink_metadata(path) }).await + blocking::spawn(move || std::fs::symlink_metadata(path)).await } diff --git a/src/fs/write.rs b/src/fs/write.rs index 4db5221..3df5604 100644 --- a/src/fs/write.rs +++ b/src/fs/write.rs @@ -33,5 +33,5 @@ use crate::task::blocking; pub async fn write, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { let path = path.as_ref().to_owned(); let contents = contents.as_ref().to_owned(); - blocking::spawn(async move { std::fs::write(path, contents) }).await + blocking::spawn(move || std::fs::write(path, contents)).await } diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 5706aa2..34d4d1d 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -116,7 +116,7 @@ impl Write for Stderr { inner.buf[..buf.len()].copy_from_slice(buf); // Start the operation asynchronously. - *state = State::Busy(blocking::spawn(async move { + *state = State::Busy(blocking::spawn(move || { let res = std::io::Write::write(&mut inner.stderr, &inner.buf); inner.last_op = Some(Operation::Write(res)); State::Idle(Some(inner)) @@ -144,7 +144,7 @@ impl Write for Stderr { let mut inner = opt.take().unwrap(); // Start the operation asynchronously. - *state = State::Busy(blocking::spawn(async move { + *state = State::Busy(blocking::spawn(move || { let res = std::io::Write::flush(&mut inner.stderr); inner.last_op = Some(Operation::Flush(res)); State::Idle(Some(inner)) diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 95a77b8..178e819 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -119,7 +119,7 @@ impl Stdin { let mut inner = opt.take().unwrap(); // Start the operation asynchronously. - *state = State::Busy(blocking::spawn(async move { + *state = State::Busy(blocking::spawn(move || { inner.line.clear(); let res = inner.stdin.read_line(&mut inner.line); inner.last_op = Some(Operation::ReadLine(res)); @@ -172,7 +172,7 @@ impl Read for Stdin { } // Start the operation asynchronously. - *state = State::Busy(blocking::spawn(async move { + *state = State::Busy(blocking::spawn(move || { let res = std::io::Read::read(&mut inner.stdin, &mut inner.buf); inner.last_op = Some(Operation::Read(res)); State::Idle(Some(inner)) diff --git a/src/io/stdout.rs b/src/io/stdout.rs index 7849f1c..4128aae 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -116,7 +116,7 @@ impl Write for Stdout { inner.buf[..buf.len()].copy_from_slice(buf); // Start the operation asynchronously. - *state = State::Busy(blocking::spawn(async move { + *state = State::Busy(blocking::spawn(move || { let res = std::io::Write::write(&mut inner.stdout, &inner.buf); inner.last_op = Some(Operation::Write(res)); State::Idle(Some(inner)) @@ -144,7 +144,7 @@ impl Write for Stdout { let mut inner = opt.take().unwrap(); // Start the operation asynchronously. - *state = State::Busy(blocking::spawn(async move { + *state = State::Busy(blocking::spawn(move || { let res = std::io::Write::flush(&mut inner.stdout); inner.last_op = Some(Operation::Flush(res)); State::Idle(Some(inner)) diff --git a/src/net/addr.rs b/src/net/addr.rs index 64b22cf..adc2408 100644 --- a/src/net/addr.rs +++ b/src/net/addr.rs @@ -196,7 +196,7 @@ impl ToSocketAddrs for (&str, u16) { } let host = host.to_string(); - let task = blocking::spawn(async move { + let task = blocking::spawn(move || { std::net::ToSocketAddrs::to_socket_addrs(&(host.as_str(), port)) }); ToSocketAddrsFuture::Resolving(task) @@ -217,8 +217,7 @@ impl ToSocketAddrs for str { } let addr = self.to_string(); - let task = - blocking::spawn(async move { std::net::ToSocketAddrs::to_socket_addrs(addr.as_str()) }); + let task = blocking::spawn(move || std::net::ToSocketAddrs::to_socket_addrs(addr.as_str())); ToSocketAddrsFuture::Resolving(task) } } diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index 1056943..1ffd636 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -76,7 +76,7 @@ impl TcpStream { let mut last_err = None; for addr in addrs.to_socket_addrs().await? { - let res = blocking::spawn(async move { + let res = blocking::spawn(move || { let std_stream = std::net::TcpStream::connect(addr)?; let mio_stream = mio::net::TcpStream::from_stream(std_stream)?; Ok(TcpStream { diff --git a/src/os/unix/fs.rs b/src/os/unix/fs.rs index f00aaec..4a15510 100644 --- a/src/os/unix/fs.rs +++ b/src/os/unix/fs.rs @@ -28,7 +28,7 @@ use crate::task::blocking; pub async fn symlink, Q: AsRef>(src: P, dst: Q) -> io::Result<()> { let src = src.as_ref().to_owned(); let dst = dst.as_ref().to_owned(); - blocking::spawn(async move { std::os::unix::fs::symlink(&src, &dst) }).await + blocking::spawn(move || std::os::unix::fs::symlink(&src, &dst)).await } cfg_if! { diff --git a/src/os/unix/net/datagram.rs b/src/os/unix/net/datagram.rs index 61adc09..c96afd5 100644 --- a/src/os/unix/net/datagram.rs +++ b/src/os/unix/net/datagram.rs @@ -67,7 +67,7 @@ impl UnixDatagram { /// ``` pub async fn bind>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - let socket = blocking::spawn(async move { mio_uds::UnixDatagram::bind(path) }).await?; + let socket = blocking::spawn(move || mio_uds::UnixDatagram::bind(path)).await?; Ok(UnixDatagram::new(socket)) } diff --git a/src/os/unix/net/listener.rs b/src/os/unix/net/listener.rs index 2d68a6b..b6e6a29 100644 --- a/src/os/unix/net/listener.rs +++ b/src/os/unix/net/listener.rs @@ -68,7 +68,7 @@ impl UnixListener { /// ``` pub async fn bind>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - let listener = blocking::spawn(async move { mio_uds::UnixListener::bind(path) }).await?; + let listener = blocking::spawn(move || mio_uds::UnixListener::bind(path)).await?; Ok(UnixListener { watcher: Watcher::new(listener), diff --git a/src/os/unix/net/stream.rs b/src/os/unix/net/stream.rs index 8245e63..b16f2a3 100644 --- a/src/os/unix/net/stream.rs +++ b/src/os/unix/net/stream.rs @@ -58,7 +58,7 @@ impl UnixStream { pub async fn connect>(path: P) -> io::Result { let path = path.as_ref().to_owned(); - blocking::spawn(async move { + blocking::spawn(move || { let std_stream = std::os::unix::net::UnixStream::connect(path)?; let mio_stream = mio_uds::UnixStream::from_stream(std_stream)?; Ok(UnixStream { diff --git a/src/task/blocking.rs b/src/task/blocking.rs index 012158d..3216012 100644 --- a/src/task/blocking.rs +++ b/src/task/blocking.rs @@ -7,7 +7,6 @@ use std::time::Duration; use crossbeam_channel::{bounded, Receiver, Sender}; use lazy_static::lazy_static; -use crate::future::Future; use crate::task::task::{JoinHandle, Tag}; use crate::utils::abort_on_panic;