From 048174012d0cd8b0d763175ec2f1556e0d6fea95 Mon Sep 17 00:00:00 2001 From: Zahari Dichev Date: Sat, 5 Sep 2020 21:32:20 +0300 Subject: [PATCH] fs: remove File::seek (#2810) Fixes: #1993 Signed-off-by: Zahari Dichev --- tokio/src/fs/file.rs | 62 ---------------------------------- tokio/tests/async_send_sync.rs | 1 - 2 files changed, 63 deletions(-) diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index b801ba999..319c2c7fc 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -202,68 +202,6 @@ impl File { } } - /// Seeks to an offset, in bytes, in a stream. - /// - /// # Examples - /// - /// ```no_run - /// use tokio::fs::File; - /// use tokio::prelude::*; - /// - /// use std::io::SeekFrom; - /// - /// # async fn dox() -> std::io::Result<()> { - /// let mut file = File::open("foo.txt").await?; - /// file.seek(SeekFrom::Start(6)).await?; - /// - /// let mut contents = vec![0u8; 10]; - /// file.read_exact(&mut contents).await?; - /// # Ok(()) - /// # } - /// ``` - /// - /// The [`read_exact`] method is defined on the [`AsyncReadExt`] trait. - /// - /// [`read_exact`]: fn@crate::io::AsyncReadExt::read_exact - /// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt - pub async fn seek(&mut self, mut pos: SeekFrom) -> io::Result { - self.complete_inflight().await; - - let mut buf = match self.state { - Idle(ref mut buf_cell) => buf_cell.take().unwrap(), - _ => unreachable!(), - }; - - // Factor in any unread data from the buf - if !buf.is_empty() { - let n = buf.discard_read(); - - if let SeekFrom::Current(ref mut offset) = pos { - *offset += n; - } - } - - let std = self.std.clone(); - - // Start the operation - self.state = Busy(sys::run(move || { - let res = (&*std).seek(pos); - (Operation::Seek(res), buf) - })); - - let (op, buf) = match self.state { - Idle(_) => unreachable!(), - Busy(ref mut rx) => rx.await.unwrap(), - }; - - self.state = Idle(Some(buf)); - - match op { - Operation::Seek(res) => res, - _ => unreachable!(), - } - } - /// Attempts to sync all OS-internal metadata to disk. /// /// This function will attempt to ensure that all in-core data reaches the diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs index 45d11bd44..f1eed0e41 100644 --- a/tokio/tests/async_send_sync.rs +++ b/tokio/tests/async_send_sync.rs @@ -152,7 +152,6 @@ async_assert_fn!(tokio::fs::DirEntry::file_type(_): Send & Sync); async_assert_fn!(tokio::fs::File::open(&str): Send & Sync); async_assert_fn!(tokio::fs::File::create(&str): Send & Sync); -async_assert_fn!(tokio::fs::File::seek(_, std::io::SeekFrom): Send & Sync); async_assert_fn!(tokio::fs::File::sync_all(_): Send & Sync); async_assert_fn!(tokio::fs::File::sync_data(_): Send & Sync); async_assert_fn!(tokio::fs::File::set_len(_, u64): Send & Sync);