Debian Codegraph @

src/base/read/io/entry.rs

raw symbols SCIP
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/::{compressedrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/::CompressedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/CompressedReader#, hashedrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/::HashedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#, ownedrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/::OwnedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/OwnedReader#};
5 use craterust-analyzer cargo async_zip 0.0.18 crate/::entryrust-analyzer cargo async_zip 0.0.18 entry/::ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#;
6 use craterust-analyzer cargo async_zip 0.0.18 crate/::errorrust-analyzer cargo async_zip 0.0.18 error/::{Resultrust-analyzer cargo async_zip 0.0.18 error/Result#, ZipErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#};
7 use craterust-analyzer cargo async_zip 0.0.18 crate/::specrust-analyzer cargo async_zip 0.0.18 spec/::Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#;
8
9 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#;
10 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/::{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#};
11
12 use futures_literust-analyzer cargo futures-lite 2.1.0 crate/::iorust-analyzer cargo futures-lite 2.1.0 io/::{AsyncBufReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncBufRead#, AsyncReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncRead#, AsyncReadExtrust-analyzer cargo futures-lite 2.1.0 io/AsyncReadExt#, Takerust-analyzer cargo futures-lite 2.1.0 io/Take#};
13 use pin_projectrust-analyzer cargo pin-project 1.0.12 crate/::pin_projectrust-analyzer cargo pin-project-internal 1.0.12 pin_project:;
14
15 /// A type which encodes that [`ZipEntryReader`] has associated entry data.
16 pub struct WithEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#<'a>(OwnedEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#<'a>);
17
18 /// A type which encodes that [`ZipEntryReader`] has no associated entry data.
19 pub struct WithoutEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithoutEntry#;
20
21 /// A ZIP entry reader which may implement decompression.
22 #[pin_projectrust-analyzer cargo pin-project-internal 1.0.12 pin_project:]
23 pub struct ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#<'a, R, E> {
24 #[pinrust-analyzer cargo pin-project-internal 1.0.12 pin:]
25 readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader.: HashedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#<CompressedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/CompressedReader#<Takerust-analyzer cargo futures-lite 2.1.0 io/Take#<OwnedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/OwnedReader#<'a, R>>>>,
26 entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry.: E,
27 }
28
29 impl<'a, R> ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#<'a, R, WithoutEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithoutEntry#>
30 where
31 R: AsyncBufReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncBufRead# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#,
32 {
33 /// Constructs a new entry reader from its required parameters (incl. an owned R).
34 pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn new_with_ownedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`]new_with_owned().(reader: R, compression: Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#, size: u64) -> Selfrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`] {
35 let reader = HashedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]new().(CompressedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/CompressedReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/impl#[`CompressedReader<R>`]new().(OwnedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/OwnedReader#::Ownedrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/OwnedReader#Owned#(reader).takerust-analyzer cargo futures-lite 2.1.0 io/AsyncReadExt#take().(size), compression));
36 Selfrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`] { readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader., entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry.: WithoutEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithoutEntry# }
37 }
38
39 /// Constructs a new entry reader from its required parameters (incl. a mutable borrow of an R).
40 pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn new_with_borrowrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`]new_with_borrow().(reader: &'a mut R, compression: Compressionrust-analyzer cargo async_zip 0.0.18 spec/compression/Compression#, size: u64) -> Selfrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`] {
41 let reader = HashedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/HashedReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]new().(CompressedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/CompressedReader#::newrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/impl#[`CompressedReader<R>`]new().(OwnedReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/OwnedReader#::Borrowrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/OwnedReader#Borrow#(reader).takerust-analyzer cargo futures-lite 2.1.0 io/AsyncReadExt#take().(size), compression));
42 Selfrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`] { readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader., entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry.: WithoutEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithoutEntry# }
43 }
44
45 pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn into_with_entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`]into_with_entry().(self, entry: &'a ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#) -> ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#<'a, R, WithEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#<'a>> {
46 ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader# { readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader.: self.readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader., entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry.: WithEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#(OwnedEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#::Borrowrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#Borrow#(entry)) }
47 }
48
49 pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn into_with_entry_ownedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, WithoutEntry>`]into_with_entry_owned().(self, entry: ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#) -> ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#<'a, R, WithEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#<'a>> {
50 ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader# { readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader.: self.readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader., entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry.: WithEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#(OwnedEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#::Ownedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#Owned#(entry)) }
51 }
52 }
53
54 impl<'a, R, E> AsyncReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncRead# for ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#<'a, R, E>
55 where
56 R: AsyncBufReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncBufRead# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#,
57 {
58 fn poll_readrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, E>`][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/entry/impl#[`ZipEntryReader<'a, R, E>`][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>> {
59 self.projectrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, E>`]project().().readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/__ZipEntryReaderProjection#reader..poll_readrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`][AsyncRead]poll_read().(c, b)
60 }
61 }
62
63 impl<'a, R, E> ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#<'a, R, E>
64 where
65 R: AsyncBufReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncBufRead# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#,
66 {
67 /// Computes and returns the CRC32 hash of bytes read by this reader so far.
68 ///
69 /// This hash should only be computed once EOF has been reached.
70 pub fn compute_hashrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, E>`]compute_hash().(&mut self) -> u32 {
71 self.readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader..swap_and_compute_hashrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]swap_and_compute_hash().()
72 }
73
74 /// Consumes this reader and returns the inner value.
75 pub(craterust-analyzer cargo async_zip 0.0.18 crate/) fn into_innerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, E>`]into_inner().(self) -> R {
76 self.readerrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#reader..into_innerrust-analyzer cargo async_zip 0.0.18 base/read/io/hashed/impl#[`HashedReader<R>`]into_inner().().into_innerrust-analyzer cargo async_zip 0.0.18 base/read/io/compressed/impl#[`CompressedReader<R>`]into_inner().().into_innerrust-analyzer cargo futures-lite 2.1.0 io/impl#[`Take<R>`]into_inner().().owned_into_innerrust-analyzer cargo async_zip 0.0.18 base/read/io/owned/impl#[`OwnedReader<'a, R>`]owned_into_inner().()
77 }
78 }
79
80 impl<R> ZipEntryReaderrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#<'_, R, WithEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#<'_>>
81 where
82 R: AsyncBufReadrust-analyzer cargo futures-io 0.3.25 if_std/AsyncBufRead# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#,
83 {
84 /// Returns an immutable reference to the associated entry data.
85 pub fn entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'_, R, WithEntry<'_>>`]entry().(&self) -> &'_ ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry# {
86 self.entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry..0rust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#0..entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`OwnedEntry<'a>`]entry().()
87 }
88
89 /// Reads all bytes until EOF has been reached, appending them to buf, and verifies the CRC32 values.
90 ///
91 /// This is a helper function synonymous to [`AsyncReadExt::read_to_end()`].
92 pub async fn read_to_end_checkedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'_, R, WithEntry<'_>>`]read_to_end_checked().(&mut self, buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo async_zip 0.0.18 error/Result#<usize> {
93 let read = self.read_to_endrust-analyzer cargo futures-lite 2.1.0 io/AsyncReadExt#read_to_end().(buf).rust-analyzer cargo futures-lite 2.1.0 io/impl#[`ReadToEndFuture<'_, R>`][Future]poll().awaitrust-analyzer cargo futures-lite 2.1.0 io/impl#[`ReadToEndFuture<'_, R>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
94
95 if self.compute_hashrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, E>`]compute_hash().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().self.entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry..0rust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#0..entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`OwnedEntry<'a>`]entry().().crc32rust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]crc32().() {
96 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read)
97 } else {
98 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ZipErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#::CRC32CheckErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#CRC32CheckError#)
99 }
100 }
101
102 /// Reads all bytes until EOF has been reached, placing them into buf, and verifies the CRC32 values.
103 ///
104 /// This is a helper function synonymous to [`AsyncReadExt::read_to_string()`].
105 pub async fn read_to_string_checkedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'_, R, WithEntry<'_>>`]read_to_string_checked().(&mut self, buf: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Resultrust-analyzer cargo async_zip 0.0.18 error/Result#<usize> {
106 let read = self.read_to_stringrust-analyzer cargo futures-lite 2.1.0 io/AsyncReadExt#read_to_string().(buf).rust-analyzer cargo futures-lite 2.1.0 io/impl#[`ReadToStringFuture<'_, R>`][Future]poll().awaitrust-analyzer cargo futures-lite 2.1.0 io/impl#[`ReadToStringFuture<'_, R>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
107
108 if self.compute_hashrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`ZipEntryReader<'a, R, E>`]compute_hash().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().self.entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/ZipEntryReader#entry..0rust-analyzer cargo async_zip 0.0.18 base/read/io/entry/WithEntry#0..entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`OwnedEntry<'a>`]entry().().crc32rust-analyzer cargo async_zip 0.0.18 entry/impl#[ZipEntry]crc32().() {
109 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read)
110 } else {
111 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ZipErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#::CRC32CheckErrorrust-analyzer cargo async_zip 0.0.18 error/ZipError#CRC32CheckError#)
112 }
113 }
114 }
115
116 enum OwnedEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#<'a> {
117 Ownedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#Owned#(ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#),
118 Borrowrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#Borrow#(&'a ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry#),
119 }
120
121 impl<'a> OwnedEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#<'a> {
122 pub fn entryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/impl#[`OwnedEntry<'a>`]entry().(&self) -> &'_ ZipEntryrust-analyzer cargo async_zip 0.0.18 entry/ZipEntry# {
123 match self {
124 OwnedEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#::Ownedrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#Owned#(entry) => entry,
125 OwnedEntryrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#::Borrowrust-analyzer cargo async_zip 0.0.18 base/read/io/entry/OwnedEntry#Borrow#(entry) => entry,
126 }
127 }
128 }