Skip to content

Commit 9126f59

Browse files
committed
fix(core): specialize output for open file when no runtime
1 parent 0a30b27 commit 9126f59

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

sqlx-core/src/fs.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use std::fs::Metadata;
33
use std::io;
44
use std::path::{Path, PathBuf};
55

6-
use cfg_if::cfg_if;
7-
8-
use crate::io::AsyncRead;
96
use crate::rt;
107

118
pub struct ReadDir {
@@ -98,17 +95,21 @@ impl ReadDir {
9895
}
9996
}
10097

101-
pub async fn open_file<P: AsRef<Path>>(path: P) -> Result<impl AsyncRead + Unpin, io::Error> {
102-
cfg_if! {
103-
if #[cfg(all(feature = "_rt-async-io", not(feature = "_rt-tokio")))] {
104-
async_fs::File::open(path).await
105-
} else {
106-
#[cfg(feature = "_rt-tokio")]
107-
if rt::rt_tokio::available() {
108-
return tokio::fs::File::open(path).await;
109-
}
110-
111-
rt::missing_rt(path)
112-
}
98+
#[cfg(feature = "_rt-tokio")]
99+
pub async fn open_file<P: AsRef<Path>>(path: P) -> Result<tokio::fs::File, io::Error> {
100+
if rt::rt_tokio::available() {
101+
return tokio::fs::File::open(path).await;
113102
}
103+
104+
rt::missing_rt(path);
105+
}
106+
107+
#[cfg(all(feature = "_rt-async-io", not(feature = "_rt-tokio")))]
108+
pub async fn open_file<P: AsRef<Path>>(path: P) -> Result<async_fs::File, io::Error> {
109+
async_fs::File::open(path).await
110+
}
111+
112+
#[cfg(all(not(feature = "_rt-async-io"), not(feature = "_rt-tokio")))]
113+
pub async fn open_file<P: AsRef<Path>>(path: P) -> Result<futures_util::io::Empty, io::Error> {
114+
rt::missing_rt(path)
114115
}

0 commit comments

Comments
 (0)