1use crate::io::{AsyncSeek, SeekFrom};
2use futures_core::future::Future;
3use futures_core::task::{Context, Poll};
4use std::io;
5use std::pin::Pin;
6
7/// Future for the [`seek`](crate::io::AsyncSeekExt::seek) method.
8#[derive(Debug)]
9#[must_use = "futures do nothing unless you `.await` or poll them"]
10pub struct Seek<'a, S: ?Sized> {
11 seek: &'a mut S,
12 pos: SeekFrom,
13}
14
15impl<S: ?Sized + Unpin> Unpin for Seek<'_, S> {}
16
17impl<'a, S: AsyncSeek + ?Sized + Unpin> Seek<'a, S> {
18 pub(super) fn new(seek: &'a mut S, pos: SeekFrom) -> Self {
19 Self { seek, pos }
20 }
21}
22
23impl<S: AsyncSeek + ?Sized + Unpin> Future for Seek<'_, S> {
24 type Output = io::Result<u64>;
25
26 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
27 let this: &mut Seek<'_, S> = &mut *self;
28 Pin::new(&mut this.seek).poll_seek(cx, this.pos)
29 }
30}
31