Skip to content

Commit 37ae28f

Browse files
committed
feat(tokio,async_io,connector): expose inner types
1 parent fd51b83 commit 37ae28f

File tree

7 files changed

+105
-20
lines changed

7 files changed

+105
-20
lines changed

src/async_io/firecracker.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::utils::{
1616

1717
pub type AsyncFirecrackerIoInner = FuturesIo<Async<UnixStream>>;
1818

19-
pub struct AsyncFirecrackerIo(AsyncFirecrackerIoInner);
19+
#[derive(Debug)]
20+
pub struct AsyncFirecrackerIo(pub AsyncFirecrackerIoInner);
2021

2122
impl AsyncFirecrackerIo {
2223
pub(super) async fn connect<P>(host_socket_path: P, guest_port: u32) -> Result<Self>
@@ -46,4 +47,16 @@ impl DerefMut for AsyncFirecrackerIo {
4647
}
4748
}
4849

50+
impl From<AsyncFirecrackerIoInner> for AsyncFirecrackerIo {
51+
fn from(inner: AsyncFirecrackerIoInner) -> Self {
52+
Self(inner)
53+
}
54+
}
55+
56+
impl From<AsyncFirecrackerIo> for AsyncFirecrackerIoInner {
57+
fn from(AsyncFirecrackerIo(inner): AsyncFirecrackerIo) -> Self {
58+
inner
59+
}
60+
}
61+
4962
hyper_io_by_deref!(AsyncFirecrackerIo);

src/async_io/unix.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use crate::utils::hyper_io_by_deref;
1212

1313
pub type AsyncUnixIoInner = FuturesIo<Async<UnixStream>>;
1414

15-
pub struct AsyncUnixIo(AsyncUnixIoInner);
15+
#[derive(Debug)]
16+
pub struct AsyncUnixIo(pub AsyncUnixIoInner);
1617

1718
impl AsyncUnixIo {
1819
pub(super) async fn connect<P>(socket_path: P) -> Result<Self>
@@ -40,4 +41,16 @@ impl DerefMut for AsyncUnixIo {
4041
}
4142
}
4243

44+
impl From<AsyncUnixIoInner> for AsyncUnixIo {
45+
fn from(inner: AsyncUnixIoInner) -> Self {
46+
Self(inner)
47+
}
48+
}
49+
50+
impl From<AsyncUnixIo> for AsyncUnixIoInner {
51+
fn from(AsyncUnixIo(inner): AsyncUnixIo) -> Self {
52+
inner
53+
}
54+
}
55+
4356
hyper_io_by_deref!(AsyncUnixIo);

src/async_io/vsock.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::utils::vsock::{check_connection, raw_connect, try_advance_cursor, try
1616

1717
pub type AsyncVsockIoInner = Async<File>;
1818

19-
pub struct AsyncVsockIo(AsyncVsockIoInner);
19+
#[derive(Debug)]
20+
pub struct AsyncVsockIo(pub AsyncVsockIoInner);
2021

2122
impl AsyncVsockIo {
2223
pub(super) async fn connect(addr: VsockAddr) -> Result<Self> {
@@ -78,6 +79,18 @@ impl DerefMut for AsyncVsockIo {
7879
}
7980
}
8081

82+
impl From<AsyncVsockIoInner> for AsyncVsockIo {
83+
fn from(inner: AsyncVsockIoInner) -> Self {
84+
Self(inner)
85+
}
86+
}
87+
88+
impl From<AsyncVsockIo> for AsyncVsockIoInner {
89+
fn from(AsyncVsockIo(inner): AsyncVsockIo) -> Self {
90+
inner
91+
}
92+
}
93+
8194
impl Read for AsyncVsockIo {
8295
#[inline(always)]
8396
fn poll_read(

src/connector/mod.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,27 @@ pub use self::vsock::VsockConnector;
3333

3434
/// This is an internal wrapper over an IO type that implements [`Write`] and
3535
/// [`Read`] that also implements [`Connection`] to achieve compatibility with hyper-util.
36-
pub struct ConnectableIo<IO>(IO);
36+
#[derive(Debug)]
37+
pub struct ConnectableIo<IO>(pub IO);
38+
39+
impl<IO> From<IO> for ConnectableIo<IO> {
40+
fn from(inner: IO) -> Self {
41+
Self(inner)
42+
}
43+
}
44+
45+
impl<IO: Write + Read + Send + Unpin> Connection for ConnectableIo<IO> {
46+
fn connected(&self) -> Connected {
47+
Connected::new()
48+
}
49+
}
50+
51+
impl<IO: Write + Read + Send + Unpin> Read for ConnectableIo<IO> {
52+
#[inline(always)]
53+
fn poll_read(self: Pin<&mut Self>, ctx: &mut Context<'_>, buf: ReadBufCursor<'_>) -> Poll<Result<()>> {
54+
Pin::new(&mut self.get_mut().0).poll_read(ctx, buf)
55+
}
56+
}
3757

3858
impl<IO: Write + Read + Send + Unpin> Write for ConnectableIo<IO> {
3959
#[inline(always)]
@@ -61,16 +81,3 @@ impl<IO: Write + Read + Send + Unpin> Write for ConnectableIo<IO> {
6181
Pin::new(&mut self.get_mut().0).poll_write_vectored(ctx, bufs)
6282
}
6383
}
64-
65-
impl<IO: Write + Read + Send + Unpin> Read for ConnectableIo<IO> {
66-
#[inline(always)]
67-
fn poll_read(self: Pin<&mut Self>, ctx: &mut Context<'_>, buf: ReadBufCursor<'_>) -> Poll<Result<()>> {
68-
Pin::new(&mut self.get_mut().0).poll_read(ctx, buf)
69-
}
70-
}
71-
72-
impl<IO: Write + Read + Send + Unpin> Connection for ConnectableIo<IO> {
73-
fn connected(&self) -> Connected {
74-
Connected::new()
75-
}
76-
}

src/tokio/firecracker.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use crate::utils::{
1717

1818
pub type TokioFirecrackerIoInner = TokioIo<UnixStream>;
1919

20-
pub struct TokioFirecrackerIo(TokioIo<UnixStream>);
20+
#[derive(Debug)]
21+
pub struct TokioFirecrackerIo(pub TokioIo<UnixStream>);
2122

2223
impl TokioFirecrackerIo {
2324
pub(super) async fn connect<P>(host_socket_path: P, guest_port: u32) -> Result<Self>
@@ -46,4 +47,16 @@ impl DerefMut for TokioFirecrackerIo {
4647
}
4748
}
4849

50+
impl From<TokioFirecrackerIoInner> for TokioFirecrackerIo {
51+
fn from(inner: TokioFirecrackerIoInner) -> Self {
52+
Self(inner)
53+
}
54+
}
55+
56+
impl From<TokioFirecrackerIo> for TokioFirecrackerIoInner {
57+
fn from(TokioFirecrackerIo(inner): TokioFirecrackerIo) -> Self {
58+
inner
59+
}
60+
}
61+
4962
hyper_io_by_deref!(TokioFirecrackerIo);

src/tokio/unix.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::utils::hyper_io_by_deref;
1111

1212
pub type TokioUnixIoInner = TokioIo<UnixStream>;
1313

14-
pub struct TokioUnixIo(TokioUnixIoInner);
14+
#[derive(Debug)]
15+
pub struct TokioUnixIo(pub TokioUnixIoInner);
1516

1617
impl TokioUnixIo {
1718
pub(super) async fn connect<P>(socket_path: P) -> Result<Self>
@@ -36,4 +37,16 @@ impl DerefMut for TokioUnixIo {
3637
}
3738
}
3839

40+
impl From<TokioUnixIoInner> for TokioUnixIo {
41+
fn from(inner: TokioUnixIoInner) -> Self {
42+
Self(inner)
43+
}
44+
}
45+
46+
impl From<TokioUnixIo> for TokioUnixIoInner {
47+
fn from(TokioUnixIo(inner): TokioUnixIo) -> Self {
48+
inner
49+
}
50+
}
51+
3952
hyper_io_by_deref!(TokioUnixIo);

src/tokio/vsock.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ pub type TokioVsockIoInner = AsyncFd<VsockStream>;
1717

1818
/// IO object representing an active VSOCK connection controlled via a Tokio [`AsyncFd`].
1919
/// This is internally a reimplementation of a relevant part of the tokio-vsock crate.
20-
pub struct TokioVsockIo(TokioVsockIoInner);
20+
#[derive(Debug)]
21+
pub struct TokioVsockIo(pub TokioVsockIoInner);
2122

2223
impl TokioVsockIo {
2324
pub(super) async fn connect(addr: VsockAddr) -> Result<Self> {
@@ -80,6 +81,18 @@ impl DerefMut for TokioVsockIo {
8081
}
8182
}
8283

84+
impl From<TokioVsockIoInner> for TokioVsockIo {
85+
fn from(inner: TokioVsockIoInner) -> Self {
86+
Self(inner)
87+
}
88+
}
89+
90+
impl From<TokioVsockIo> for TokioVsockIoInner {
91+
fn from(TokioVsockIo(inner): TokioVsockIo) -> Self {
92+
inner
93+
}
94+
}
95+
8396
impl Read for TokioVsockIo {
8497
#[inline(always)]
8598
fn poll_read(

0 commit comments

Comments
 (0)