mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
fs: use FileOptions inside fs::File to support uring (#7617)
This commit is contained in:
@@ -150,10 +150,7 @@ impl File {
|
|||||||
/// [`read_to_end`]: fn@crate::io::AsyncReadExt::read_to_end
|
/// [`read_to_end`]: fn@crate::io::AsyncReadExt::read_to_end
|
||||||
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
|
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
|
||||||
pub async fn open(path: impl AsRef<Path>) -> io::Result<File> {
|
pub async fn open(path: impl AsRef<Path>) -> io::Result<File> {
|
||||||
let path = path.as_ref().to_owned();
|
Self::options().read(true).open(path).await
|
||||||
let std = asyncify(|| StdFile::open(path)).await?;
|
|
||||||
|
|
||||||
Ok(File::from_std(std))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Opens a file in write-only mode.
|
/// Opens a file in write-only mode.
|
||||||
@@ -188,9 +185,12 @@ impl File {
|
|||||||
/// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all
|
/// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all
|
||||||
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
|
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
|
||||||
pub async fn create(path: impl AsRef<Path>) -> io::Result<File> {
|
pub async fn create(path: impl AsRef<Path>) -> io::Result<File> {
|
||||||
let path = path.as_ref().to_owned();
|
Self::options()
|
||||||
let std_file = asyncify(move || StdFile::create(path)).await?;
|
.write(true)
|
||||||
Ok(File::from_std(std_file))
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(path)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Opens a file in read-write mode.
|
/// Opens a file in read-write mode.
|
||||||
|
|||||||
Reference in New Issue
Block a user