From fd7d0ad5e57e968cd45a3dba75250ea272e32e10 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 1 Sep 2023 09:01:22 -0400 Subject: [PATCH] io: add `SyncIOBridge::into_inner` (#5971) --- tokio-util/src/io/sync_bridge.rs | 5 +++++ tokio-util/tests/io_sync_bridge.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tokio-util/src/io/sync_bridge.rs b/tokio-util/src/io/sync_bridge.rs index f87bfbb9c..678ce099a 100644 --- a/tokio-util/src/io/sync_bridge.rs +++ b/tokio-util/src/io/sync_bridge.rs @@ -140,4 +140,9 @@ impl SyncIoBridge { pub fn new_with_handle(src: T, rt: tokio::runtime::Handle) -> Self { Self { src, rt } } + + /// Consume this bridge, returning the underlying stream. + pub fn into_inner(self) -> T { + self.src + } } diff --git a/tokio-util/tests/io_sync_bridge.rs b/tokio-util/tests/io_sync_bridge.rs index 76bbd0b4e..50d0e8961 100644 --- a/tokio-util/tests/io_sync_bridge.rs +++ b/tokio-util/tests/io_sync_bridge.rs @@ -43,6 +43,18 @@ async fn test_async_write_to_sync() -> Result<(), Box> { Ok(()) } +#[tokio::test] +async fn test_into_inner() -> Result<(), Box> { + let mut buf = Vec::new(); + SyncIoBridge::new(tokio::io::empty()) + .into_inner() + .read_to_end(&mut buf) + .await + .unwrap(); + assert_eq!(buf.len(), 0); + Ok(()) +} + #[tokio::test] async fn test_shutdown() -> Result<(), Box> { let (s1, mut s2) = tokio::io::duplex(1024);