From 45574512574e77011964e45fe58ec2d09ba60367 Mon Sep 17 00:00:00 2001 From: David Yamnitsky Date: Sat, 7 Oct 2023 08:43:35 -0400 Subject: [PATCH] io: implement `Seek` for `SyncIoBridge` (#6058) --- tokio-util/src/io/sync_bridge.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tokio-util/src/io/sync_bridge.rs b/tokio-util/src/io/sync_bridge.rs index 678ce099ac1..2402207584c 100644 --- a/tokio-util/src/io/sync_bridge.rs +++ b/tokio-util/src/io/sync_bridge.rs @@ -1,6 +1,7 @@ -use std::io::{BufRead, Read, Write}; +use std::io::{BufRead, Read, Seek, Write}; use tokio::io::{ - AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, + AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncSeek, AsyncSeekExt, AsyncWrite, + AsyncWriteExt, }; /// Use a [`tokio::io::AsyncRead`] synchronously as a [`std::io::Read`] or @@ -79,6 +80,13 @@ impl Write for SyncIoBridge { } } +impl Seek for SyncIoBridge { + fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result { + let src = &mut self.src; + self.rt.block_on(AsyncSeekExt::seek(src, pos)) + } +} + // Because https://doc.rust-lang.org/std/io/trait.Write.html#method.is_write_vectored is at the time // of this writing still unstable, we expose this as part of a standalone method. impl SyncIoBridge {