async_std/io/seek/
mod.rs

1mod seek;
2
3use seek::SeekFuture;
4
5use crate::io::SeekFrom;
6
7pub use futures_io::AsyncSeek as Seek;
8
9#[doc = r#"
10    Extension methods for [`Seek`].
11
12    [`Seek`]: ../trait.Seek.html
13"#]
14pub trait SeekExt: Seek {
15    #[doc = r#"
16        Seeks to a new position in a byte stream.
17
18        Returns the new position in the byte stream.
19
20        A seek beyond the end of stream is allowed, but behavior is defined by the
21        implementation.
22
23        # Examples
24
25        ```no_run
26        # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
27        #
28        use async_std::fs::File;
29        use async_std::io::SeekFrom;
30        use async_std::prelude::*;
31
32        let mut file = File::open("a.txt").await?;
33
34        let file_len = file.seek(SeekFrom::End(0)).await?;
35        #
36        # Ok(()) }) }
37        ```
38    "#]
39    fn seek(
40        &mut self,
41        pos: SeekFrom,
42    ) -> SeekFuture<'_, Self>
43    where
44        Self: Unpin,
45    {
46        SeekFuture { seeker: self, pos }
47    }
48}
49
50impl<T: Seek + ?Sized> SeekExt for T {}