| 1 | use 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/; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/; |
| 4 | use 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/::{Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#, ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#}; |
| 5 | |
| 6 | use superrust-analyzer cargo buffered-reader 1.4.1 crate/::*; |
| 7 | |
| 8 | /// Controls tracing. |
| 9 | const TRACErust-analyzer cargo buffered-reader 1.4.1 generic/TRACE.: bool = false; |
| 10 | |
| 11 | /// Wraps a `Read`er. |
| 12 | /// |
| 13 | /// This is useful when reading from a generic `std::io::Read`er. To |
| 14 | /// read from a file, use [`File`]. To read from a buffer, use |
| 15 | /// [`Memory`]. Both are more efficient than `Generic`. |
| 16 | /// |
| 17 | pub struct Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> { |
| 18 | bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 19 | // The next byte to read in the buffer. |
| 20 | cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor.: usize, |
| 21 | /// Currently unused buffer. |
| 22 | unused_bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#unused_buffer.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 23 | // The preferred chunk size. This is just a hint. |
| 24 | preferred_chunk_sizerust-analyzer cargo buffered-reader 1.4.1 generic/Generic#preferred_chunk_size.: usize, |
| 25 | // The wrapped reader. |
| 26 | readerrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#reader.: T, |
| 27 | // Stashed error, if any. |
| 28 | errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#>, |
| 29 | /// Whether we hit EOF on the underlying reader. |
| 30 | eofrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#eof.: bool, |
| 31 | |
| 32 | // The user settable cookie. |
| 33 | cookierust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cookie.: C, |
| 34 | } |
| 35 | |
| 36 | assert_send_and_syncrust-analyzer cargo buffered-reader 1.4.1 macros/assert_send_and_sync!!(Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T, C> |
| 37 | where T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, |
| 38 | C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#); |
| 39 | |
| 40 | impl<T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T, C> { |
| 41 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 42 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Generic") |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | impl<T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T, C> { |
| 47 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 48 | let buffered_data = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref buffer) = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer. { |
| 49 | buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]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().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. |
| 50 | } else { |
| 51 | 0 |
| 52 | }; |
| 53 | |
| 54 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("Generic") |
| 55 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("preferred_chunk_size", &self.preferred_chunk_sizerust-analyzer cargo buffered-reader 1.4.1 generic/Generic#preferred_chunk_size.) |
| 56 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("buffer data", &buffered_data) |
| 57 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | impl<T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#> Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T, ()> { |
| 62 | /// Instantiate a new generic reader. `reader` is the source to |
| 63 | /// wrap. `preferred_chunk_size` is the preferred chunk size. If |
| 64 | /// None, then the default will be used, which is usually what you |
| 65 | /// want. |
| 66 | pub fn newrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, ()>`]new().(reader: T, preferred_chunk_size: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) -> Selfrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, ()>`] { |
| 67 | Selfrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, ()>`]::with_cookierust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]with_cookie().(reader, preferred_chunk_size, ()) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl<T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T, C> { |
| 72 | /// Like [`Self::new`], but sets a cookie, which can be retrieved using |
| 73 | /// the [`BufferedReader::cookie_ref`] and [`BufferedReader::cookie_mut`] methods, and set using |
| 74 | /// the [`BufferedReader::cookie_set`] method. |
| 75 | pub fn with_cookierust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]with_cookie().( |
| 76 | reader: T, preferred_chunk_size: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, cookie: C) |
| 77 | -> Selfrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`] { |
| 78 | Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic# { |
| 79 | bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 80 | cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor.: 0, |
| 81 | unused_bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#unused_buffer.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 82 | preferred_chunk_sizerust-analyzer cargo buffered-reader 1.4.1 generic/Generic#preferred_chunk_size.: |
| 83 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = preferred_chunk_size { s } |
| 84 | else { default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().() }, |
| 85 | readerrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#reader., |
| 86 | errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 87 | eofrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#eof.: false, |
| 88 | cookierust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cookie., |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /// Returns a reference to the wrapped writer. |
| 93 | pub fn reader_refrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]reader_ref().(&self) -> &T { |
| 94 | &self.readerrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#reader. |
| 95 | } |
| 96 | |
| 97 | /// Returns a mutable reference to the wrapped writer. |
| 98 | pub fn reader_mutrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]reader_mut().(&mut self) -> &mut T { |
| 99 | &mut self.readerrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#reader. |
| 100 | } |
| 101 | |
| 102 | /// Returns the wrapped writer. |
| 103 | pub fn into_readerrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]into_reader().(self) -> T { |
| 104 | self.readerrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#reader. |
| 105 | } |
| 106 | |
| 107 | /// Return the buffer. Ensure that it contains at least `amount` |
| 108 | /// bytes. |
| 109 | // |
| 110 | // Note: |
| 111 | // |
| 112 | // If you find a bug in this function, consider whether |
| 113 | // sequoia_openpgp::armor::Reader::data_helper is also affected. |
| 114 | fn data_helperrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]data_helper().(&mut self, amount: usize, hard: bool, and_consume: bool) |
| 115 | -> 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]> { |
| 116 | tracerrust-analyzer cargo buffered-reader 1.4.1 macros/tracer!!(TRACE, "Generic::data_helper"); |
| 117 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("amount: {}, hard: {}, and_consume: {} (cursor: {}, buffer: {:?})", |
| 118 | amount, hard, and_consume, |
| 119 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor., |
| 120 | self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|buffer| buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().())); |
| 121 | |
| 122 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref buffer) = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer. { |
| 123 | // We have a buffer. Make sure `cursor` is sane. |
| 124 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. <= buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 125 | } else { |
| 126 | // We don't have a buffer. Make sure cursor is 0. |
| 127 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor., 0); |
| 128 | } |
| 129 | |
| 130 | let amount_buffered |
| 131 | = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|b| b.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]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().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor.).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0); |
| 132 | if amount 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().amount_buffered { |
| 133 | // The caller wants more data than we have readily |
| 134 | // available. Read some more. |
| 135 | |
| 136 | let capacity : usize = amount.saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_add().( |
| 137 | default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().().maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().( |
| 138 | self.preferred_chunk_sizerust-analyzer cargo buffered-reader 1.4.1 generic/Generic#preferred_chunk_size..saturating_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_mul().(2))); |
| 139 | |
| 140 | let mut buffer_new = self.unused_bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#unused_buffer..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() |
| 141 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|mut v| { |
| 142 | vec_resizerust-analyzer cargo buffered-reader 1.4.1 vec_resize().(&mut v, capacity); |
| 143 | v |
| 144 | }) |
| 145 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; capacity]); |
| 146 | |
| 147 | let mut amount_read = 0; |
| 148 | while amount_buffered 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().amount_read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().amount { |
| 149 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Have {} bytes, need {} bytes", |
| 150 | amount_buffered +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). amount_read, amount); |
| 151 | |
| 152 | if self.eofrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#eof. { |
| 153 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Hit EOF on the underlying reader, don't poll again."); |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | // See if there is an error from the last invocation. |
| 158 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) = &self.errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error. { |
| 159 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("We have a stashed error, don't poll again: {}", e); |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | match self.readerrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#reader..readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read().(&mut buffer_new |
| 164 | [rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().amount_buffered 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().amount_read..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().) { |
| 165 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read) => { |
| 166 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Read {} bytes", read); |
| 167 | if read 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().0 { |
| 168 | self.eofrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#eof. = true; |
| 169 | break; |
| 170 | } else { |
| 171 | amount_read 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().read; |
| 172 | continue; |
| 173 | } |
| 174 | }, |
| 175 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ref err) if err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Interruptedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Interrupted# => |
| 176 | continue, |
| 177 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => { |
| 178 | // Don't return yet, because we may have |
| 179 | // actually read something. |
| 180 | self.errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(err); |
| 181 | break; |
| 182 | }, |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if amount_read 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 { |
| 187 | // We read something. |
| 188 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref buffer) = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer. { |
| 189 | // We need to copy in the old data. |
| 190 | buffer_new[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#amount_buffered]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 191 | .copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().( |
| 192 | &buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. 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().amount_buffered]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 193 | } |
| 194 | |
| 195 | vec_truncaterust-analyzer cargo buffered-reader 1.4.1 vec_truncate().(&mut buffer_new, amount_buffered 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().amount_read); |
| 196 | |
| 197 | self.unused_bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#unused_buffer. = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().(); |
| 198 | self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(buffer_new); |
| 199 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. = 0; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | let amount_buffered |
| 204 | = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|b| b.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]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().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor.).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0); |
| 205 | |
| 206 | if self.errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 207 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Encountered an error: {}", self.errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 208 | // An error occurred. If we have enough data to fulfill |
| 209 | // the caller's request, then don't return the error. |
| 210 | if hard && amount 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().amount_buffered { |
| 211 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Not enough data to fulfill request, returning error"); |
| 212 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(self.errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 213 | } |
| 214 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().hard && amount_buffered 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().0 { |
| 215 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("No data data buffered, returning error"); |
| 216 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(self.errorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#error..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | if hard && amount_buffered rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().amount { |
| 221 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Unexpected EOF"); |
| 222 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#, "EOF")) |
| 223 | } else if amount 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().0 || amount_buffered 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().0 { |
| 224 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Returning zero-length slice"); |
| 225 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&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/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 226 | } else { |
| 227 | let buffer = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 228 | if and_consume { |
| 229 | let amount_consumed = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(amount_buffered, amount); |
| 230 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. 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().amount_consumed; |
| 231 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. <= buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 232 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Consuming {} bytes, returning {} bytes", |
| 233 | amount_consumed, |
| 234 | buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor.-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().amount_consumed..]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 235 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor.-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().amount_consumed..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 236 | } else { |
| 237 | trust-analyzer cargo buffered-reader 1.4.1 generic/t!!("Returning {} bytes", |
| 238 | buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 239 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | impl<T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T, C> { |
| 246 | fn readrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][Read]read().(&mut self, buf: &mut [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 247 | buffered_reader_generic_read_implrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_generic_read_impl().(self, buf) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | impl<T: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> for Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<T, C> { |
| 252 | fn bufferrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]buffer().(&self) -> &[u8] { |
| 253 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref buffer) = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer. { |
| 254 | &buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 255 | } else { |
| 256 | &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/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | fn datarust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data().(&mut self, amount: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 261 | self.data_helperrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]data_helper().(amount, false, false) |
| 262 | } |
| 263 | |
| 264 | fn data_hardrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data_hard().(&mut self, amount: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 265 | self.data_helperrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]data_helper().(amount, true, false) |
| 266 | } |
| 267 | |
| 268 | // Note: |
| 269 | // |
| 270 | // If you find a bug in this function, consider whether |
| 271 | // sequoia_openpgp::armor::Reader::consume is also affected. |
| 272 | fn consumerust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]consume().(&mut self, amount: usize) -> &[u8] { |
| 273 | // println!("Generic.consume({}) \ |
| 274 | // (cursor: {}, buffer: {:?})", |
| 275 | // amount, self.cursor, |
| 276 | // if let Some(ref buffer) = self.buffer { Some(buffer.len()) } |
| 277 | // else { None }); |
| 278 | |
| 279 | // The caller can't consume more than is buffered! |
| 280 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref buffer) = self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer. { |
| 281 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. <= buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 282 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(amount <= buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor., |
| 283 | "buffer contains just {} bytes, but you are trying to \ |
| 284 | consume {} bytes. Did you forget to call data()?", |
| 285 | buffer.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor., amount); |
| 286 | |
| 287 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. 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().amount; |
| 288 | return &self.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#buffer..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.cursorrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cursor. 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().amount..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 289 | } else { |
| 290 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(amount, 0); |
| 291 | &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/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | fn data_consumerust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data_consume().(&mut self, amount: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 296 | self.data_helperrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]data_helper().(amount, false, true) |
| 297 | } |
| 298 | |
| 299 | fn data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data_consume_hard().(&mut self, amount: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 300 | self.data_helperrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]data_helper().(amount, true, true) |
| 301 | } |
| 302 | |
| 303 | fn get_mutrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]get_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut dyn BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>> { |
| 304 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 305 | } |
| 306 | |
| 307 | fn get_refrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]get_ref().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&dyn BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>> { |
| 308 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 309 | } |
| 310 | |
| 311 | fn into_innerrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]into_inner().<'b>(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> + 'b>> |
| 312 | where Selfrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]: 'b { |
| 313 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 314 | } |
| 315 | |
| 316 | fn cookie_setrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]cookie_set().(&mut self, cookie: C) -> C { |
| 317 | use 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/; |
| 318 | |
| 319 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.cookierust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cookie., cookie) |
| 320 | } |
| 321 | |
| 322 | fn cookie_refrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]cookie_ref().(&self) -> &C { |
| 323 | &self.cookierust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cookie. |
| 324 | } |
| 325 | |
| 326 | fn cookie_mutrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]cookie_mut().(&mut self) -> &mut C { |
| 327 | &mut self.cookierust-analyzer cargo buffered-reader 1.4.1 generic/Generic#cookie. |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | #[cfg(test)] |
| 332 | mod testrust-analyzer cargo buffered-reader 1.4.1 generic/test/ { |
| 333 | use superrust-analyzer cargo buffered-reader 1.4.1 generic/::*; |
| 334 | |
| 335 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 336 | fn buffered_reader_generic_testrust-analyzer cargo buffered-reader 1.4.1 generic/test/buffered_reader_generic_test().() { |
| 337 | // Test reading from a file. |
| 338 | { |
| 339 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#; |
| 340 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 341 | |
| 342 | let path : PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf# = [envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/env!!("CARGO_MANIFEST_DIR"), |
| 343 | "src", "buffered-reader-test.txt"] |
| 344 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 345 | let mut f = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(&path).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|_| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("{}", path.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().())); |
| 346 | let mut bio = Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#::newrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, ()>`]new().(&mut f, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 347 | |
| 348 | buffered_reader_test_data_checkrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_test_data_check().(&mut bio); |
| 349 | } |
| 350 | |
| 351 | // Same test, but as a slice. |
| 352 | { |
| 353 | let mut bio = Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#::newrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, ()>`]new().(craterust-analyzer cargo buffered-reader 1.4.1 crate/::BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 354 | |
| 355 | buffered_reader_test_data_checkrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_test_data_check().(&mut bio); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // Test that buffer() returns the same data as data(). |
| 360 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 361 | fn buffer_testrust-analyzer cargo buffered-reader 1.4.1 generic/test/buffer_test().() { |
| 362 | // Test vector. |
| 363 | let size = 10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().(); |
| 364 | let mut input = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(size); |
| 365 | let mut v = 0u8; |
| 366 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#size { |
| 367 | input.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(v); |
| 368 | if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::u8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u8/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/u8/MAX. { |
| 369 | v = 0; |
| 370 | } else { |
| 371 | v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().1; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | let mut reader = Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#::newrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, ()>`]new().(&input[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 376 | |
| 377 | // Gather some stats to make it easier to figure out whether |
| 378 | // this test is working. |
| 379 | let stats_count = 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().(); |
| 380 | let mut stats = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0usize; stats_count]; |
| 381 | |
| 382 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#input.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 383 | let data = reader.datarust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data().(default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().() 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().1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 384 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().data.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()); |
| 385 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data, reader.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]buffer().()); |
| 386 | // And, we may as well check to make sure we read the |
| 387 | // right data. |
| 388 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(data, &input[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i..i+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().); |
| 389 | |
| 390 | stats[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), stats_count 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().1)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). 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; |
| 391 | |
| 392 | // Consume one byte and see what happens. |
| 393 | reader.consumerust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]consume().(1); |
| 394 | } |
| 395 | |
| 396 | if false { |
| 397 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#stats.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 398 | if stats[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). 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 { |
| 399 | if i 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().stats.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]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().1 { |
| 400 | eprintrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprint!!(">="); |
| 401 | } |
| 402 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{}: {}", i, stats[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /// Tests that we can request some data using data_hard even if a |
| 409 | /// previous request for more data failed. |
| 410 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 411 | fn data_hard_after_failurerust-analyzer cargo buffered-reader 1.4.1 generic/test/data_hard_after_failure().() -> 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#<()> { |
| 412 | /// Returns one byte once, then errors. |
| 413 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 414 | struct BuggySourcerust-analyzer cargo buffered-reader 1.4.1 generic/test/BuggySource#(bool); |
| 415 | impl iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for BuggySourcerust-analyzer cargo buffered-reader 1.4.1 generic/test/BuggySource# { |
| 416 | fn readrust-analyzer cargo buffered-reader 1.4.1 generic/test/impl#[BuggySource][Read]read().(&mut self, _: &mut [u8]) -> 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> { |
| 417 | if self.0rust-analyzer cargo buffered-reader 1.4.1 generic/test/BuggySource#0. { |
| 418 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, "oops")) |
| 419 | } else { |
| 420 | self.0rust-analyzer cargo buffered-reader 1.4.1 generic/test/BuggySource#0. = true; |
| 421 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(1) |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | let mut br = Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#::newrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, ()>`]new().(BuggySourcerust-analyzer cargo buffered-reader 1.4.1 generic/test/BuggySource#::defaultrust-analyzer cargo buffered-reader 1.4.1 generic/test/impl#[BuggySource][Default]default().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 427 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(br.datarust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data().(2).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); // Ok... |
| 428 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(br.datarust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 1); // ... but short. |
| 429 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(br.data_hardrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data_hard().(1).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); // Should be fine then. |
| 430 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 431 | } |
| 432 | } |