| 1 | // Copyright (c) 2022 Harry [Majored] [[email protected]] |
| 2 | // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE) |
| 3 | |
| 4 | use craterust-analyzer cargo async_zip 0.0.18 crate/::baserust-analyzer cargo async_zip 0.0.18 base/::readrust-analyzer cargo async_zip 0.0.18 base/read/::iorust-analyzer cargo async_zip 0.0.18 base/read/io/::poll_result_okrust-analyzer cargo async_zip 0.0.18 base/read/io/poll_result_ok!; |
| 5 | |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::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#; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::{readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/ready/ready!, 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#}; |
| 8 | |
| 9 | use crc32fastrust-analyzer cargo crc32fast 1.4.2 crate/::Hasherrust-analyzer cargo crc32fast 1.4.2 Hasher#; |
| 10 | use futures_literust-analyzer cargo futures-lite 2.1.0 crate/::iorust-analyzer cargo futures-lite 2.1.0 io/::AsyncReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncRead#; |
| 11 | use pin_projectrust-analyzer cargo pin-project 1.0.12 crate/::pin_projectrust-analyzer cargo pin-project-internal 1.0.12 pin_project:; |
| 12 | |
| 13 | /// A wrapping reader which computes the CRC32 hash of data read via [`AsyncRead`]. |
| 14 | #[pin_projectrust-analyzer cargo pin-project-internal 1.0.12 pin_project:] |
| 15 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) struct HashedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#<R> { |
| 16 | #[pinrust-analyzer cargo pin-project-internal 1.0.12 pin:] |
| 17 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) readerrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#reader.: R, |
| 18 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) hasherrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#hasher.: Hasherrust-analyzer cargo crc32fast 1.4.2 Hasher#, |
| 19 | } |
| 20 | |
| 21 | impl<R> HashedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#<R> |
| 22 | where |
| 23 | R: AsyncReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncRead# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#, |
| 24 | { |
| 25 | /// Constructs a new wrapping reader from a generic [`AsyncRead`] implementer. |
| 26 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn newrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]new().(reader: R) -> Selfrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`] { |
| 27 | Selfrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`] { readerrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#reader., hasherrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#hasher.: Hasherrust-analyzer cargo crc32fast 1.4.2 Hasher#::defaultrust-analyzer cargo crc32fast 1.4.2 impl#[Hasher][Default]default().() } |
| 28 | } |
| 29 | |
| 30 | /// Swaps the internal hasher and returns the computed CRC32 hash. |
| 31 | /// |
| 32 | /// The internal hasher is taken and replaced with a newly-constructed one. As a result, this method should only be |
| 33 | /// called once EOF has been reached and it's known that no more data will be read, else the computed hash(s) won't |
| 34 | /// accurately represent the data read in. |
| 35 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn swap_and_compute_hashrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]swap_and_compute_hash().(&mut self) -> u32 { |
| 36 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.hasherrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#hasher.).finalizerust-analyzer cargo crc32fast 1.4.2 impl#[Hasher]finalize().() |
| 37 | } |
| 38 | |
| 39 | /// Consumes this reader and returns the inner value. |
| 40 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn into_innerrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]into_inner().(self) -> R { |
| 41 | self.readerrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#reader. |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl<R> AsyncReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncRead# for HashedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#<R> |
| 46 | where |
| 47 | R: AsyncReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncRead# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#, |
| 48 | { |
| 49 | fn poll_readrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`][AsyncRead]poll_read().(self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`][AsyncRead]>, c: &mut Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>, b: &mut [u8]) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::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#<usize>> { |
| 50 | let project = self.projectrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]project().(); |
| 51 | let written = poll_result_okrust-analyzer cargo async_zip 0.0.18 base/read/io/poll_result_ok!!(readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/ready/ready!!(project.readerrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/__HashedReaderProjection#reader..poll_readrust-analyzer cargo futures-io 0.3.25 if_std/AsyncRead#poll_read().(c, b))); |
| 52 | project.hasherrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/__HashedReaderProjection#hasher..updaterust-analyzer cargo crc32fast 1.4.2 impl#[Hasher]update().(&b[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#written]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 53 | |
| 54 | 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#(written)) |
| 55 | } |
| 56 | } |