buf_list/cursor/
futures_imp.rs

1// Copyright (c) The buf-list Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{BufList, Cursor};
5use futures_io_03::{AsyncBufRead, AsyncRead, AsyncSeek};
6use std::{
7    io::{self, IoSliceMut, SeekFrom},
8    pin::Pin,
9    task::{Context, Poll},
10};
11
12impl<T: AsRef<BufList> + Unpin> AsyncSeek for Cursor<T> {
13    fn poll_seek(
14        mut self: Pin<&mut Self>,
15        _: &mut Context<'_>,
16        pos: SeekFrom,
17    ) -> Poll<io::Result<u64>> {
18        Poll::Ready(io::Seek::seek(&mut *self, pos))
19    }
20}
21
22impl<T: AsRef<BufList> + Unpin> AsyncRead for Cursor<T> {
23    fn poll_read(
24        mut self: Pin<&mut Self>,
25        _cx: &mut Context<'_>,
26        buf: &mut [u8],
27    ) -> Poll<io::Result<usize>> {
28        Poll::Ready(io::Read::read(&mut *self, buf))
29    }
30
31    fn poll_read_vectored(
32        mut self: Pin<&mut Self>,
33        _: &mut Context<'_>,
34        bufs: &mut [IoSliceMut<'_>],
35    ) -> Poll<io::Result<usize>> {
36        Poll::Ready(io::Read::read_vectored(&mut *self, bufs))
37    }
38}
39
40impl<T: AsRef<BufList> + Unpin> AsyncBufRead for Cursor<T> {
41    fn poll_fill_buf(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
42        Poll::Ready(io::BufRead::fill_buf(self.get_mut()))
43    }
44
45    fn consume(mut self: Pin<&mut Self>, amt: usize) {
46        io::BufRead::consume(&mut *self, amt)
47    }
48}