2018-06-21 18:43:35 +02:00
|
|
|
use super::File;
|
2019-07-11 11:05:49 -05:00
|
|
|
use std::future::Future;
|
2018-06-21 18:43:35 +02:00
|
|
|
use std::io;
|
2019-07-11 11:05:49 -05:00
|
|
|
use std::pin::Pin;
|
|
|
|
|
use std::task::Context;
|
|
|
|
|
use std::task::Poll;
|
2018-06-21 18:43:35 +02:00
|
|
|
|
2018-07-12 00:09:37 +02:00
|
|
|
/// Future returned by `File::seek`.
|
2018-06-21 18:43:35 +02:00
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct SeekFuture {
|
|
|
|
|
inner: Option<File>,
|
|
|
|
|
pos: io::SeekFrom,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SeekFuture {
|
|
|
|
|
pub(crate) fn new(file: File, pos: io::SeekFrom) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
pos,
|
|
|
|
|
inner: Some(file),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Future for SeekFuture {
|
2019-07-11 11:05:49 -05:00
|
|
|
type Output = io::Result<(File, u64)>;
|
2018-06-21 18:43:35 +02:00
|
|
|
|
2019-07-11 11:05:49 -05:00
|
|
|
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
|
|
|
let inner_self = Pin::get_mut(self);
|
|
|
|
|
let pos = ready!(inner_self
|
2019-02-21 11:56:15 -08:00
|
|
|
.inner
|
|
|
|
|
.as_mut()
|
|
|
|
|
.expect("Cannot poll `SeekFuture` after it resolves")
|
2019-07-11 11:05:49 -05:00
|
|
|
.poll_seek(inner_self.pos))?;
|
|
|
|
|
let inner = inner_self.inner.take().unwrap();
|
|
|
|
|
Poll::Ready(Ok((inner, pos).into()))
|
2018-06-21 18:43:35 +02:00
|
|
|
}
|
|
|
|
|
}
|