| 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 | |
| 5 | 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#}; |
| 6 | |
| 7 | use superrust-analyzer cargo buffered-reader 1.4.1 crate/::*; |
| 8 | |
| 9 | /// Wraps a memory buffer. |
| 10 | /// |
| 11 | /// Although it is possible to use `Generic` to wrap a |
| 12 | /// buffer, this implementation is optimized for a memory buffer, and |
| 13 | /// avoids double buffering. |
| 14 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 15 | pub struct Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'a, 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#> { |
| 16 | bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer.: &'a [u8], |
| 17 | // The next byte to read in the buffer. |
| 18 | cursorrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cursor.: usize, |
| 19 | |
| 20 | // The user settable cookie. |
| 21 | cookierust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cookie.: C, |
| 22 | } |
| 23 | |
| 24 | assert_send_and_syncrust-analyzer cargo buffered-reader 1.4.1 macros/assert_send_and_sync!!(Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'_, C> |
| 25 | where 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#); |
| 26 | |
| 27 | impl<'a, 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 Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'a, C> { |
| 28 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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# { |
| 29 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Memory ({} of {} bytes read)", |
| 30 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cursor., self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl<'a> Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'a, ()> { |
| 35 | /// Instantiates a new `Memory`. |
| 36 | /// |
| 37 | /// `buffer` contains the `Memory`'s contents. |
| 38 | pub fn newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]new().(buffer: &'a [u8]) -> Selfrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`] { |
| 39 | Selfrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]::with_cookierust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]with_cookie().(buffer, ()) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | impl<'a, 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#> Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'a, C> { |
| 44 | /// Like [`Self::new`], but sets a cookie. |
| 45 | /// |
| 46 | /// The cookie can be retrieved using the [`BufferedReader::cookie_ref`] and |
| 47 | /// [`BufferedReader::cookie_mut`] methods, and set using the [`BufferedReader::cookie_set`] method. |
| 48 | pub fn with_cookierust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]with_cookie().(buffer: &'a [u8], cookie: C) -> Selfrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`] { |
| 49 | Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory# { |
| 50 | bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer., |
| 51 | cursorrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cursor.: 0, |
| 52 | cookierust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cookie., |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /// Returns the number of bytes that have been consumed by this |
| 57 | /// reader. |
| 58 | pub fn total_outrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]total_out().(&self) -> usize { |
| 59 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cursor. |
| 60 | } |
| 61 | |
| 62 | #[allow(dead_code)] |
| 63 | pub(craterust-analyzer cargo buffered-reader 1.4.1 crate/) fn source_bufferrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]source_buffer().(&self) -> &[u8] { |
| 64 | self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer. |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | impl<'a, 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 Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'a, C> { |
| 69 | fn readrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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#> { |
| 70 | let amount = 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().(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]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 memory/Memory#cursor.); |
| 71 | buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#amount]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().( |
| 72 | &self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#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 memory/Memory#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 memory/Memory#cursor.+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().amount]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 73 | self.consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]consume().(amount); |
| 74 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(amount) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | impl<'a, 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 Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'a, C> { |
| 79 | fn bufferrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]buffer().(&self) -> &[u8] { |
| 80 | &self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#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 memory/Memory#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(). |
| 81 | } |
| 82 | |
| 83 | fn datarust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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#> { |
| 84 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.cursorrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cursor. <= self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 85 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#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 memory/Memory#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().) |
| 86 | } |
| 87 | |
| 88 | fn consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]consume().(&mut self, amount: usize) -> &[u8] { |
| 89 | // The caller can't consume more than is buffered! |
| 90 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(amount <= self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]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 memory/Memory#cursor., |
| 91 | "Attempt to consume {} bytes, but buffer only has {} bytes!", |
| 92 | amount, self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]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 memory/Memory#cursor.); |
| 93 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#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; |
| 94 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.cursorrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cursor. <= self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 95 | &self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#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 memory/Memory#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(). |
| 96 | } |
| 97 | |
| 98 | fn data_consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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#> { |
| 99 | let amount = 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, self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]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 memory/Memory#cursor.); |
| 100 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]consume().(amount)); |
| 101 | } |
| 102 | |
| 103 | fn data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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#> { |
| 104 | if self.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#buffer..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]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 memory/Memory#cursor. 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 { |
| 105 | return 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")); |
| 106 | } |
| 107 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]consume().(amount)); |
| 108 | } |
| 109 | |
| 110 | fn get_mutrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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>> { |
| 111 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 112 | } |
| 113 | |
| 114 | fn get_refrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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>> { |
| 115 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 116 | } |
| 117 | |
| 118 | fn into_innerrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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 memory/impl#[`Memory<'a, 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>> |
| 119 | where Selfrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]: 'b { |
| 120 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 121 | } |
| 122 | |
| 123 | fn cookie_setrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]cookie_set().(&mut self, cookie: C) -> C { |
| 124 | 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/; |
| 125 | |
| 126 | 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 memory/Memory#cookie., cookie) |
| 127 | } |
| 128 | |
| 129 | fn cookie_refrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]cookie_ref().(&self) -> &C { |
| 130 | &self.cookierust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cookie. |
| 131 | } |
| 132 | |
| 133 | fn cookie_mutrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]cookie_mut().(&mut self) -> &mut C { |
| 134 | &mut self.cookierust-analyzer cargo buffered-reader 1.4.1 memory/Memory#cookie. |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | #[cfg(test)] |
| 139 | mod testrust-analyzer cargo buffered-reader 1.4.1 memory/test/ { |
| 140 | use superrust-analyzer cargo buffered-reader 1.4.1 memory/::*; |
| 141 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 142 | fn buffered_reader_memory_testrust-analyzer cargo buffered-reader 1.4.1 memory/test/buffered_reader_memory_test(). () { |
| 143 | let mut bio = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]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.); |
| 144 | |
| 145 | buffered_reader_test_data_checkrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_test_data_check().(&mut bio); |
| 146 | } |
| 147 | |
| 148 | // Test that buffer() returns the same data as data(). |
| 149 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 150 | fn buffer_testrust-analyzer cargo buffered-reader 1.4.1 memory/test/buffer_test().() { |
| 151 | // Test vector. A Memory returns all unconsumed |
| 152 | // data. So, use a relatively small buffer size. |
| 153 | let size = default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().(); |
| 154 | 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); |
| 155 | let mut v = 0u8; |
| 156 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#size { |
| 157 | input.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(v); |
| 158 | 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. { |
| 159 | v = 0; |
| 160 | } else { |
| 161 | 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; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | let mut reader = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]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().); |
| 166 | |
| 167 | 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().() { |
| 168 | let data = reader.datarust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, 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().(); |
| 169 | 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().()); |
| 170 | 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 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]buffer().()); |
| 171 | // And, we may as well check to make sure we read the |
| 172 | // right data. |
| 173 | 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().); |
| 174 | |
| 175 | // Consume one byte and see what happens. |
| 176 | reader.consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]consume().(1); |
| 177 | } |
| 178 | } |
| 179 | } |