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

refactor: name buffer type parameters B #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl File {
/// })
/// }
/// ```
pub async fn read_at<T: BoundedBufMut>(&self, buf: T, pos: u64) -> crate::BufResult<usize, T> {
pub async fn read_at<B: BoundedBufMut>(&self, buf: B, pos: u64) -> crate::BufResult<usize, B> {
// Submit the read operation
let op = Op::read_at(&self.fd, buf, pos).unwrap();
op.await
Expand Down Expand Up @@ -227,11 +227,11 @@ impl File {
/// })
/// }
/// ```
pub async fn readv_at<T: BoundedBufMut>(
pub async fn readv_at<B: BoundedBufMut>(
&self,
bufs: Vec<T>,
bufs: Vec<B>,
pos: u64,
) -> crate::BufResult<usize, Vec<T>> {
) -> crate::BufResult<usize, Vec<B>> {
// Submit the read operation
let op = Op::readv_at(&self.fd, bufs, pos).unwrap();
op.await
Expand Down Expand Up @@ -392,13 +392,13 @@ impl File {
/// ```
///
/// [`ErrorKind::UnexpectedEof`]: std::io::ErrorKind::UnexpectedEof
pub async fn read_exact_at<T>(&self, buf: T, pos: u64) -> crate::BufResult<(), T>
pub async fn read_exact_at<B>(&self, buf: B, pos: u64) -> crate::BufResult<(), B>
where
T: BoundedBufMut,
B: BoundedBufMut,
{
let orig_bounds = buf.bounds();
let (res, buf) = self.read_exact_slice_at(buf.slice_full(), pos).await;
(res, T::from_buf_bounds(buf, orig_bounds))
(res, B::from_buf_bounds(buf, orig_bounds))
}

async fn read_exact_slice_at<T: IoBufMut>(
Expand Down Expand Up @@ -484,9 +484,9 @@ impl File {
/// })
///# }
/// ```
pub async fn read_fixed_at<T>(&self, buf: T, pos: u64) -> crate::BufResult<usize, T>
pub async fn read_fixed_at<B>(&self, buf: B, pos: u64) -> crate::BufResult<usize, B>
where
T: BoundedBufMut<BufMut = FixedBuf>,
B: BoundedBufMut<BufMut = FixedBuf>,
{
// Submit the read operation
let op = Op::read_fixed_at(&self.fd, buf, pos).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/io/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub(crate) struct Read<T> {
pub(crate) buf: T,
}

impl<T: BoundedBufMut> Op<Read<T>> {
pub(crate) fn read_at(fd: &SharedFd, buf: T, offset: u64) -> io::Result<Op<Read<T>>> {
impl<B: BoundedBufMut> Op<Read<B>> {
pub(crate) fn read_at(fd: &SharedFd, buf: B, offset: u64) -> io::Result<Op<Read<B>>> {
use io_uring::{opcode, types};

CONTEXT.with(|x| {
Expand All @@ -39,11 +39,11 @@ impl<T: BoundedBufMut> Op<Read<T>> {
}
}

impl<T> Completable for Read<T>
impl<B> Completable for Read<B>
where
T: BoundedBufMut,
B: BoundedBufMut,
{
type Output = BufResult<usize, T>;
type Output = BufResult<usize, B>;

fn complete(self, cqe: CqeResult) -> Self::Output {
// Convert the operation result to `usize`
Expand Down
14 changes: 7 additions & 7 deletions src/io/read_fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ pub(crate) struct ReadFixed<T> {
buf: T,
}

impl<T> Op<ReadFixed<T>>
impl<B> Op<ReadFixed<B>>
where
T: BoundedBufMut<BufMut = FixedBuf>,
B: BoundedBufMut<BufMut = FixedBuf>,
{
pub(crate) fn read_fixed_at(
fd: &SharedFd,
buf: T,
buf: B,
offset: u64,
) -> io::Result<Op<ReadFixed<T>>> {
) -> io::Result<Op<ReadFixed<B>>> {
use io_uring::{opcode, types};

CONTEXT.with(|x| {
Expand All @@ -48,11 +48,11 @@ where
}
}

impl<T> Completable for ReadFixed<T>
impl<B> Completable for ReadFixed<B>
where
T: BoundedBufMut<BufMut = FixedBuf>,
B: BoundedBufMut<BufMut = FixedBuf>,
{
type Output = BufResult<usize, T>;
type Output = BufResult<usize, B>;

fn complete(self, cqe: op::CqeResult) -> Self::Output {
// Convert the operation result to `usize`
Expand Down
12 changes: 6 additions & 6 deletions src/io/readv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub(crate) struct Readv<T> {
iovs: Vec<iovec>,
}

impl<T: BoundedBufMut> Op<Readv<T>> {
impl<B: BoundedBufMut> Op<Readv<B>> {
pub(crate) fn readv_at(
fd: &SharedFd,
mut bufs: Vec<T>,
mut bufs: Vec<B>,
offset: u64,
) -> io::Result<Op<Readv<T>>> {
) -> io::Result<Op<Readv<B>>> {
use io_uring::{opcode, types};

// Build `iovec` objects referring the provided `bufs` for `io_uring::opcode::Readv`.
Expand Down Expand Up @@ -58,11 +58,11 @@ impl<T: BoundedBufMut> Op<Readv<T>> {
}
}

impl<T> Completable for Readv<T>
impl<B> Completable for Readv<B>
where
T: BoundedBufMut,
B: BoundedBufMut,
{
type Output = BufResult<usize, Vec<T>>;
type Output = BufResult<usize, Vec<B>>;

fn complete(self, cqe: CqeResult) -> Self::Output {
// Convert the operation result to `usize`
Expand Down
10 changes: 5 additions & 5 deletions src/io/recv_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub(crate) struct RecvFrom<T> {
pub(crate) msghdr: Box<libc::msghdr>,
}

impl<T: BoundedBufMut> Op<RecvFrom<T>> {
pub(crate) fn recv_from(fd: &SharedFd, mut buf: T) -> io::Result<Op<RecvFrom<T>>> {
impl<B: BoundedBufMut> Op<RecvFrom<B>> {
pub(crate) fn recv_from(fd: &SharedFd, mut buf: B) -> io::Result<Op<RecvFrom<B>>> {
use io_uring::{opcode, types};

let mut io_slices = vec![IoSliceMut::new(unsafe {
Expand Down Expand Up @@ -53,11 +53,11 @@ impl<T: BoundedBufMut> Op<RecvFrom<T>> {
}
}

impl<T> Completable for RecvFrom<T>
impl<B> Completable for RecvFrom<B>
where
T: BoundedBufMut,
B: BoundedBufMut,
{
type Output = BufResult<(usize, SocketAddr), T>;
type Output = BufResult<(usize, SocketAddr), B>;

fn complete(self, cqe: CqeResult) -> Self::Output {
// Convert the operation result to `usize`
Expand Down
10 changes: 5 additions & 5 deletions src/io/recvmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub(crate) struct RecvMsg<T> {
pub(crate) msghdr: Box<libc::msghdr>,
}

impl<T: BoundedBufMut> Op<RecvMsg<T>> {
pub(crate) fn recvmsg(fd: &SharedFd, mut bufs: Vec<T>) -> io::Result<Op<RecvMsg<T>>> {
impl<B: BoundedBufMut> Op<RecvMsg<B>> {
pub(crate) fn recvmsg(fd: &SharedFd, mut bufs: Vec<B>) -> io::Result<Op<RecvMsg<B>>> {
use io_uring::{opcode, types};

let mut io_slices = Vec::with_capacity(bufs.len());
Expand Down Expand Up @@ -57,11 +57,11 @@ impl<T: BoundedBufMut> Op<RecvMsg<T>> {
}
}

impl<T> Completable for RecvMsg<T>
impl<B> Completable for RecvMsg<B>
where
T: BoundedBufMut,
B: BoundedBufMut,
{
type Output = BufResult<(usize, SocketAddr), Vec<T>>;
type Output = BufResult<(usize, SocketAddr), Vec<B>>;

fn complete(self, cqe: CqeResult) -> Self::Output {
// Convert the operation result to `usize`
Expand Down
18 changes: 9 additions & 9 deletions src/io/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,31 +168,31 @@ impl Socket {
op.await
}

pub(crate) async fn read<T: BoundedBufMut>(&self, buf: T) -> crate::BufResult<usize, T> {
pub(crate) async fn read<B: BoundedBufMut>(&self, buf: B) -> crate::BufResult<usize, B> {
let op = Op::read_at(&self.fd, buf, 0).unwrap();
op.await
}

pub(crate) async fn read_fixed<T>(&self, buf: T) -> crate::BufResult<usize, T>
pub(crate) async fn read_fixed<B>(&self, buf: B) -> crate::BufResult<usize, B>
where
T: BoundedBufMut<BufMut = FixedBuf>,
B: BoundedBufMut<BufMut = FixedBuf>,
{
let op = Op::read_fixed_at(&self.fd, buf, 0).unwrap();
op.await
}

pub(crate) async fn recv_from<T: BoundedBufMut>(
pub(crate) async fn recv_from<B: BoundedBufMut>(
&self,
buf: T,
) -> crate::BufResult<(usize, SocketAddr), T> {
buf: B,
) -> crate::BufResult<(usize, SocketAddr), B> {
let op = Op::recv_from(&self.fd, buf).unwrap();
op.await
}

pub(crate) async fn recvmsg<T: BoundedBufMut>(
pub(crate) async fn recvmsg<B: BoundedBufMut>(
&self,
buf: Vec<T>,
) -> crate::BufResult<(usize, SocketAddr), Vec<T>> {
buf: Vec<B>,
) -> crate::BufResult<(usize, SocketAddr), Vec<B>> {
let op = Op::recvmsg(&self.fd, buf).unwrap();
op.await
}
Expand Down
6 changes: 3 additions & 3 deletions src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl TcpStream {
/// Read some data from the stream into the buffer.
///
/// Returns the original buffer and quantity of data read.
pub async fn read<T: BoundedBufMut>(&self, buf: T) -> crate::BufResult<usize, T> {
pub async fn read<B: BoundedBufMut>(&self, buf: B) -> crate::BufResult<usize, B> {
self.inner.read(buf).await
}

Expand All @@ -91,9 +91,9 @@ impl TcpStream {
/// In addition to errors that can be reported by `read`,
/// this operation fails if the buffer is not registered in the
/// current `tokio-uring` runtime.
pub async fn read_fixed<T>(&self, buf: T) -> crate::BufResult<usize, T>
pub async fn read_fixed<B>(&self, buf: B) -> crate::BufResult<usize, B>
where
T: BoundedBufMut<BufMut = FixedBuf>,
B: BoundedBufMut<BufMut = FixedBuf>,
{
self.inner.read_fixed(buf).await
}
Expand Down
18 changes: 9 additions & 9 deletions src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,27 +296,27 @@ impl UdpSocket {
/// Receives a single datagram message on the socket.
///
/// On success, returns the number of bytes read and the origin.
pub async fn recv_from<T: BoundedBufMut>(
pub async fn recv_from<B: BoundedBufMut>(
&self,
buf: T,
) -> crate::BufResult<(usize, SocketAddr), T> {
buf: B,
) -> crate::BufResult<(usize, SocketAddr), B> {
self.inner.recv_from(buf).await
}

/// Receives a single datagram message on the socket, into multiple buffers
///
/// On success, returns the number of bytes read and the origin.
pub async fn recvmsg<T: BoundedBufMut>(
pub async fn recvmsg<B: BoundedBufMut>(
&self,
buf: Vec<T>,
) -> crate::BufResult<(usize, SocketAddr), Vec<T>> {
buf: Vec<B>,
) -> crate::BufResult<(usize, SocketAddr), Vec<B>> {
self.inner.recvmsg(buf).await
}

/// Reads a packet of data from the socket into the buffer.
///
/// Returns the original buffer and quantity of data read.
pub async fn read<T: BoundedBufMut>(&self, buf: T) -> crate::BufResult<usize, T> {
pub async fn read<B: BoundedBufMut>(&self, buf: B) -> crate::BufResult<usize, B> {
self.inner.read(buf).await
}

Expand All @@ -333,9 +333,9 @@ impl UdpSocket {
/// In addition to errors that can be reported by `read`,
/// this operation fails if the buffer is not registered in the
/// current `tokio-uring` runtime.
pub async fn read_fixed<T>(&self, buf: T) -> crate::BufResult<usize, T>
pub async fn read_fixed<B>(&self, buf: B) -> crate::BufResult<usize, B>
where
T: BoundedBufMut<BufMut = FixedBuf>,
B: BoundedBufMut<BufMut = FixedBuf>,
{
self.inner.read_fixed(buf).await
}
Expand Down
6 changes: 3 additions & 3 deletions src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl UnixStream {

/// Read some data from the stream into the buffer, returning the original buffer and
/// quantity of data read.
pub async fn read<T: BoundedBufMut>(&self, buf: T) -> crate::BufResult<usize, T> {
pub async fn read<B: BoundedBufMut>(&self, buf: B) -> crate::BufResult<usize, B> {
self.inner.read(buf).await
}

Expand All @@ -90,9 +90,9 @@ impl UnixStream {
/// In addition to errors that can be reported by `read`,
/// this operation fails if the buffer is not registered in the
/// current `tokio-uring` runtime.
pub async fn read_fixed<T>(&self, buf: T) -> crate::BufResult<usize, T>
pub async fn read_fixed<B>(&self, buf: B) -> crate::BufResult<usize, B>
where
T: BoundedBufMut<BufMut = FixedBuf>,
B: BoundedBufMut<BufMut = FixedBuf>,
{
self.inner.read_fixed(buf).await
}
Expand Down