| 1 | // Copyright (c) The buf-list Contributors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | use superrust-analyzer cargo buf-list 1.1.2 cursor/::CursorDatarust-analyzer cargo buf-list 1.1.2 cursor/CursorData#; |
| 5 | use craterust-analyzer cargo buf-list 1.1.2 crate/::{BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#, Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#}; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 7 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#}, |
| 8 | pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#, |
| 9 | taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::{Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#, Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#}, |
| 10 | }; |
| 11 | use tokiorust-analyzer cargo tokio 1.6.1 crate/::iorust-analyzer cargo tokio 1.6.1 io/::{AsyncBufReadrust-analyzer cargo tokio 1.6.1 io/async_buf_read/AsyncBufRead#, AsyncReadrust-analyzer cargo tokio 1.6.1 io/async_read/AsyncRead#, AsyncSeekrust-analyzer cargo tokio 1.6.1 io/async_seek/AsyncSeek#, ReadBufrust-analyzer cargo tokio 1.6.1 io/read_buf/ReadBuf#}; |
| 12 | |
| 13 | impl<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#> + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#> AsyncSeekrust-analyzer cargo tokio 1.6.1 io/async_seek/AsyncSeek# for Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#<T> { |
| 14 | fn start_seekrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncSeek]start_seek().(mut self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncSeek]>, pos: SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 15 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#::seekrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][Seek]seek().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`][DerefMut]deref_mut().self, pos).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().) |
| 16 | } |
| 17 | |
| 18 | fn poll_completerust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncSeek]poll_complete().(self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncSeek]>, _: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u64>> { |
| 19 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<&'a mut T>`]get_mut().().positionrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`]position().())) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | impl<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#> + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#> AsyncReadrust-analyzer cargo tokio 1.6.1 io/async_read/AsyncRead# for Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#<T> { |
| 24 | fn poll_readrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncRead]poll_read().( |
| 25 | mut self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncRead]>, |
| 26 | _: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>, |
| 27 | buf: &mut ReadBufrust-analyzer cargo tokio 1.6.1 io/read_buf/ReadBuf#<'_>, |
| 28 | ) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>> { |
| 29 | let this = &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`][DerefMut]deref_mut().self; |
| 30 | this.datarust-analyzer cargo buf-list 1.1.2 cursor/Cursor#data..tokio_poll_read_implrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[CursorData]tokio_poll_read_impl().(this.innerrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#inner..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), buf) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl<T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#> + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#> AsyncBufReadrust-analyzer cargo tokio 1.6.1 io/async_buf_read/AsyncBufRead# for Cursorrust-analyzer cargo buf-list 1.1.2 cursor/Cursor#<T> { |
| 35 | fn poll_fill_bufrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncBufRead]poll_fill_buf().(self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncBufRead]>, _: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&[u8]>> { |
| 36 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#::fill_bufrust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][BufRead]fill_buf().(self.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<&'a mut T>`]get_mut().())) |
| 37 | } |
| 38 | |
| 39 | fn consumerust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncBufRead]consume().(mut self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[`Cursor<T>`][AsyncBufRead]>, amt: usize) { |
| 40 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#::consumerust-analyzer cargo buf-list 1.1.2 cursor/impl#[`Cursor<T>`][BufRead]consume().(&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`][DerefMut]deref_mut().self, amt) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl CursorDatarust-analyzer cargo buf-list 1.1.2 cursor/CursorData# { |
| 45 | fn tokio_poll_read_implrust-analyzer cargo buf-list 1.1.2 cursor/tokio_imp/impl#[CursorData]tokio_poll_read_impl().( |
| 46 | &mut self, |
| 47 | list: &BufListrust-analyzer cargo buf-list 1.1.2 imp/BufList#, |
| 48 | buf: &mut ReadBufrust-analyzer cargo tokio 1.6.1 io/read_buf/ReadBuf#<'_>, |
| 49 | ) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>> { |
| 50 | // This is really similar to Self::read_impl, except it's written against the ReadBuf API. |
| 51 | while buf.remainingrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]remaining().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 52 | let (chunk, chunk_pos) = match self.get_chunk_and_posrust-analyzer cargo buf-list 1.1.2 cursor/impl#[CursorData]get_chunk_and_pos().(list) { |
| 53 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) => value, |
| 54 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break, |
| 55 | }; |
| 56 | // The number of bytes to copy is the smaller of the two: |
| 57 | // - the length of the chunk - the position in it. |
| 58 | // - the number of bytes remaining. |
| 59 | let n_to_copy = (chunk.lenrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().chunk_pos).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(buf.remainingrust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]remaining().()); |
| 60 | let chunk_bytes = chunk.as_refrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes][`AsRef<[u8]>`]as_ref().(); |
| 61 | |
| 62 | let bytes_to_copy = &chunk_bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().chunk_pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(chunk_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().n_to_copy)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 63 | buf.put_slicerust-analyzer cargo tokio 1.6.1 io/read_buf/impl#[`ReadBuf<'a>`]put_slice().(bytes_to_copy); |
| 64 | |
| 65 | // Increment the position. |
| 66 | self.posrust-analyzer cargo buf-list 1.1.2 cursor/CursorData#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().n_to_copy as u64; |
| 67 | // If we've finished reading through the chunk, move to the next chunk. |
| 68 | if n_to_copy rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().chunk.lenrust-analyzer cargo bytes 1.3.0 bytes/impl#[Bytes]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().chunk_pos { |
| 69 | self.chunkrust-analyzer cargo buf-list 1.1.2 cursor/CursorData#chunk. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())) |
| 74 | } |
| 75 | } |