Skip to content

Commit

Permalink
fs: implement fs::File::from_std
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Oct 13, 2022
1 parent a42af77 commit 4dee10a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
///
Expand Down

0 comments on commit 4dee10a

Please sign in to comment.