From 4dee10a9982e5a3fd55eaac9634e2370b837487c Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 13 Oct 2022 03:14:52 +0000 Subject: [PATCH] fs: implement fs::File::from_std --- src/fs/file.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index e451fadc..d3ec027e 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -4,7 +4,7 @@ use crate::fs::OpenOptions; use std::fmt; use std::io; -use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use std::path::Path; /// A reference to an open file on the filesystem. @@ -120,6 +120,14 @@ impl File { File { fd } } + /// Converts a [`std::fs::File`][std] to a [`tokio_uring::fs::File`][file]. + /// + /// [std]: std::fs::File + /// [file]: File + pub fn from_std(file: std::fs::File) -> File { + File::from_shared_fd(SharedFd::new(file.into_raw_fd())) + } + /// Read some bytes at the specified offset from the file into the specified /// buffer, returning how many bytes were read. ///