From bba4b45664a132aa57d91a1b73fc64159d812622 Mon Sep 17 00:00:00 2001 From: Oliver Bunting <72926894+ollie-etl@users.noreply.github.com> Date: Thu, 15 Feb 2024 08:36:15 +0000 Subject: [PATCH] Expose trait externally --- src/fs/file.rs | 2 +- src/io/read.rs | 2 +- src/io/readv.rs | 2 +- src/io/recv_from.rs | 2 +- src/io/recvmsg.rs | 2 +- src/io/send_to.rs | 2 +- src/io/send_zc.rs | 2 +- src/io/write.rs | 2 +- src/io/write_fixed.rs | 2 +- src/io/writev.rs | 2 +- src/types.rs | 31 ++++++++++++++++++------------- 11 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index ebf061ad..451223ac 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -4,7 +4,7 @@ use crate::fs::OpenOptions; use crate::io::SharedFd; use crate::runtime::driver::op::Op; -use crate::sealed::MapResult; +use crate::MapResult; use crate::{UnsubmittedOneshot, UnsubmittedWrite}; use std::fmt; use std::io; diff --git a/src/io/read.rs b/src/io/read.rs index d87af8c1..c98ed532 100644 --- a/src/io/read.rs +++ b/src/io/read.rs @@ -1,7 +1,7 @@ use crate::buf::BoundedBufMut; use crate::io::SharedFd; -use crate::sealed::WithBuffer; use crate::Result; +use crate::WithBuffer; use crate::runtime::driver::op::{Completable, CqeResult, Op}; use crate::runtime::CONTEXT; diff --git a/src/io/readv.rs b/src/io/readv.rs index 44843a21..9fc0a902 100644 --- a/src/io/readv.rs +++ b/src/io/readv.rs @@ -1,6 +1,6 @@ use crate::buf::BoundedBufMut; -use crate::sealed::WithBuffer; use crate::Result; +use crate::WithBuffer; use crate::io::SharedFd; use crate::runtime::driver::op::{Completable, CqeResult, Op}; diff --git a/src/io/recv_from.rs b/src/io/recv_from.rs index f7537801..2dc979a9 100644 --- a/src/io/recv_from.rs +++ b/src/io/recv_from.rs @@ -1,6 +1,6 @@ use crate::runtime::driver::op::{Completable, CqeResult, Op}; use crate::runtime::CONTEXT; -use crate::sealed::WithBuffer; +use crate::WithBuffer; use crate::{buf::BoundedBufMut, io::SharedFd, Result}; use socket2::SockAddr; use std::{ diff --git a/src/io/recvmsg.rs b/src/io/recvmsg.rs index 71dc8215..ad634422 100644 --- a/src/io/recvmsg.rs +++ b/src/io/recvmsg.rs @@ -1,6 +1,6 @@ use crate::runtime::driver::op::{Completable, CqeResult, Op}; use crate::runtime::CONTEXT; -use crate::sealed::WithBuffer; +use crate::WithBuffer; use crate::{buf::BoundedBufMut, io::SharedFd, Result}; use socket2::SockAddr; use std::{ diff --git a/src/io/send_to.rs b/src/io/send_to.rs index e41cd399..9a15210c 100644 --- a/src/io/send_to.rs +++ b/src/io/send_to.rs @@ -2,8 +2,8 @@ use crate::buf::BoundedBuf; use crate::io::SharedFd; use crate::runtime::driver::op::{Completable, CqeResult, Op}; use crate::runtime::CONTEXT; -use crate::sealed::WithBuffer; use crate::Result; +use crate::WithBuffer; use socket2::SockAddr; use std::io::IoSlice; use std::{boxed::Box, io, net::SocketAddr}; diff --git a/src/io/send_zc.rs b/src/io/send_zc.rs index 838e1801..f15ccbe7 100644 --- a/src/io/send_zc.rs +++ b/src/io/send_zc.rs @@ -1,6 +1,6 @@ use crate::runtime::driver::op::{Completable, CqeResult, MultiCQEFuture, Op, Updateable}; use crate::runtime::CONTEXT; -use crate::sealed::WithBuffer; +use crate::WithBuffer; use crate::{buf::BoundedBuf, io::SharedFd, Result}; use std::io; diff --git a/src/io/write.rs b/src/io/write.rs index 72bee1d8..e2a95f32 100644 --- a/src/io/write.rs +++ b/src/io/write.rs @@ -1,4 +1,4 @@ -use crate::sealed::WithBuffer; +use crate::WithBuffer; use crate::{buf::BoundedBuf, io::SharedFd, OneshotOutputTransform, Result, UnsubmittedOneshot}; use io_uring::cqueue::Entry; use std::io; diff --git a/src/io/write_fixed.rs b/src/io/write_fixed.rs index d99e74d0..9119e8c9 100644 --- a/src/io/write_fixed.rs +++ b/src/io/write_fixed.rs @@ -2,8 +2,8 @@ use crate::buf::fixed::FixedBuf; use crate::buf::BoundedBuf; use crate::io::SharedFd; use crate::runtime::driver::op::{self, Completable, Op}; -use crate::sealed::WithBuffer; use crate::Result; +use crate::WithBuffer; use crate::runtime::CONTEXT; use std::io; diff --git a/src/io/writev.rs b/src/io/writev.rs index e73de206..a2833100 100644 --- a/src/io/writev.rs +++ b/src/io/writev.rs @@ -1,6 +1,6 @@ use crate::runtime::driver::op::{Completable, CqeResult, Op}; use crate::runtime::CONTEXT; -use crate::sealed::WithBuffer; +use crate::WithBuffer; use crate::{buf::BoundedBuf, io::SharedFd, Result}; use libc::iovec; use std::io; diff --git a/src/types.rs b/src/types.rs index c063eddd..40742bd8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -61,21 +61,26 @@ impl Error { } } -pub(super) mod sealed { - /// A Specialized trait for mapping over the buffer in both sides of a Result - pub trait MapResult { - type Output; - fn map_buf(self, f: impl FnOnce(B) -> U) -> Self::Output; - } +mod private { + pub trait Sealed {} +} +impl private::Sealed for std::result::Result {} - /// Adapter trait to convert result::Result to crate::Result where E can be - /// converted to std::io::Error. - pub trait WithBuffer: Sized { - fn with_buffer(self, buf: B) -> T; - } +/// A Specialized trait for mapping over the buffer in both sides of a Result +pub trait MapResult: private::Sealed { + /// The result type after applying the map operation + type Output; + /// Apply a function over the buffer on both sides of the result + fn map_buf(self, f: impl FnOnce(B) -> U) -> Self::Output; } -impl sealed::MapResult for Result { +/// Adapter trait to convert result::Result to crate::Result where E can be +/// converted to std::io::Error. +pub trait WithBuffer: private::Sealed { + /// Insert a buffer into each side of the result + fn with_buffer(self, buf: B) -> T; +} +impl MapResult for Result { type Output = Result; fn map_buf(self, f: impl FnOnce(B) -> U) -> Self::Output { match self { @@ -86,7 +91,7 @@ impl sealed::MapResult for Result { } /// Adaptor implementation for Result to Result. -impl sealed::WithBuffer, B> for std::result::Result +impl WithBuffer, B> for std::result::Result where E: Into, {