Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl AsyncReadRentAt and AsyncWriteRentAt for File #309

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion monoio/src/fs/file/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{io, path::Path};
use std::{future::Future, io, path::Path};

use crate::{
buf::{IoBuf, IoBufMut, IoVecBuf, IoVecBufMut},
driver::{op::Op, shared_fd::SharedFd},
fs::OpenOptions,
io::{AsyncReadRent, AsyncWriteRent},
BufResult,
};

#[cfg(unix)]
Expand All @@ -16,6 +17,8 @@ mod windows;
#[cfg(windows)]
use windows as file_impl;

use crate::io::{AsyncReadRentAt, AsyncWriteRentAt};

/// A reference to an open file on the filesystem.
///
/// An instance of a `File` can be read and/or written depending on what options
Expand Down Expand Up @@ -635,6 +638,16 @@ impl AsyncWriteRent for File {
}
}

impl AsyncWriteRentAt for File {
fn write_at<T: IoBuf>(
&mut self,
buf: T,
pos: usize,
) -> impl Future<Output = BufResult<usize, T>> {
File::write_at(self, buf, pos as u64)
}
}

impl AsyncReadRent for File {
/// Reads bytes from the file at the current file pointer into the specified buffer, returning
/// the number of bytes read.
Expand Down Expand Up @@ -753,3 +766,13 @@ impl AsyncReadRent for File {
self.read_vectored(buf).await
}
}

impl AsyncReadRentAt for File {
fn read_at<T: IoBufMut>(
&mut self,
buf: T,
pos: usize,
) -> impl Future<Output = BufResult<usize, T>> {
File::read_at(self, buf, pos as u64)
}
}
Loading