use std::io::{self, SeekFrom};
use std::ops::DerefMut;
use std::pin::Pin;
use std::task::{Context, Poll};
pub trait AsyncSeek {
fn poll_seek(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
pos: SeekFrom,
) -> Poll<io::Result<u64>>;
}
impl<P: DerefMut + Unpin> AsyncSeek for Pin<P>
where
P::Target: AsyncSeek,
{
fn poll_seek(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
pos: SeekFrom,
) -> Poll<io::Result<u64>> {
self.get_mut().as_mut().poll_seek(cx, pos)
}
}
impl<S: AsyncSeek + Unpin + ?Sized> AsyncSeek for Box<S> {
fn poll_seek(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
pos: SeekFrom,
) -> Poll<io::Result<u64>> {
Pin::new(&mut **self).poll_seek(cx, pos)
}
}
impl<S: AsyncSeek + Unpin + ?Sized> AsyncSeek for &mut S {
fn poll_seek(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
pos: SeekFrom,
) -> Poll<io::Result<u64>> {
Pin::new(&mut **self).poll_seek(cx, pos)
}
}