Skip to content

Commit

Permalink
fs: implement FromRawFd for File (#89)
Browse files Browse the repository at this point in the history
Implement FromRawFd for File, so we could convert a normal file into
tokio-uring File.

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
  • Loading branch information
jiangliu authored Jul 12, 2022
1 parent 1055958 commit 9b9c500
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 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, RawFd};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::path::Path;

/// A reference to an open file on the filesystem.
Expand Down Expand Up @@ -330,6 +330,12 @@ impl File {
}
}

impl FromRawFd for File {
unsafe fn from_raw_fd(fd: RawFd) -> Self {
File::from_shared_fd(SharedFd::new(fd))
}
}

impl AsRawFd for File {
fn as_raw_fd(&self) -> RawFd {
self.fd.raw_fd()
Expand Down

0 comments on commit 9b9c500

Please sign in to comment.