Skip to content

Commit

Permalink
io: add SyncIOBridge::into_inner (#5971)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Sep 1, 2023
1 parent 37bb47c commit fd7d0ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tokio-util/src/io/sync_bridge.rs
Expand Up @@ -140,4 +140,9 @@ impl<T: Unpin> SyncIoBridge<T> {
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
}
}
12 changes: 12 additions & 0 deletions tokio-util/tests/io_sync_bridge.rs
Expand Up @@ -43,6 +43,18 @@ async fn test_async_write_to_sync() -> Result<(), Box<dyn Error>> {
Ok(())
}

#[tokio::test]
async fn test_into_inner() -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
let (s1, mut s2) = tokio::io::duplex(1024);
Expand Down

0 comments on commit fd7d0ad

Please sign in to comment.