| 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 superrust-analyzer cargo buffered-reader 1.4.1 crate/::*; |
| 6 | |
| 7 | /// Duplicates the underlying `BufferedReader` without consuming any |
| 8 | /// of the data. |
| 9 | /// |
| 10 | /// Note: this will likely cause the underlying stream to buffer as |
| 11 | /// much data as you read. Thus, it should only be used for peeking |
| 12 | /// at the underlying `BufferedReader`. |
| 13 | #[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:)] |
| 14 | pub struct Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#<T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>, 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#> { |
| 15 | // The number of bytes that have been consumed. |
| 16 | cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor.: usize, |
| 17 | |
| 18 | // The user settable cookie. |
| 19 | cookierust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cookie.: C, |
| 20 | |
| 21 | readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader.: T, |
| 22 | } |
| 23 | |
| 24 | assert_send_and_syncrust-analyzer cargo buffered-reader 1.4.1 macros/assert_send_and_sync!!(Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#<T, C> |
| 25 | where T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>, |
| 26 | 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#); |
| 27 | |
| 28 | impl<T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>, 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 Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#<T, C> { |
| 29 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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# { |
| 30 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("Dup") |
| 31 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("cursor", &self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor.) |
| 32 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | impl<T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<()>> Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#<T, ()> { |
| 37 | /// Instantiates a new `Dup` buffered reader. |
| 38 | /// |
| 39 | /// `reader` is the `BufferedReader` to duplicate. |
| 40 | pub fn newrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, ()>`]new().(reader: T) -> Selfrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, ()>`] { |
| 41 | Selfrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, ()>`]::with_cookierust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`]with_cookie().(reader, ()) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl<T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>, 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#> Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#<T, C> { |
| 46 | /// Like [`Self::new`], but uses a cookie. |
| 47 | /// |
| 48 | /// The cookie can be retrieved using the [`BufferedReader::cookie_ref`] and |
| 49 | /// [`BufferedReader::cookie_mut`] methods, and set using the [`BufferedReader::cookie_set`] method. |
| 50 | pub fn with_cookierust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`]with_cookie().(reader: T, cookie: C) -> Selfrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`] { |
| 51 | Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup# { |
| 52 | readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader., |
| 53 | cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor.: 0, |
| 54 | cookierust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cookie., |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /// Returns the number of bytes that this reader has consumed. |
| 59 | pub fn total_outrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`]total_out().(&self) -> usize { |
| 60 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor. |
| 61 | } |
| 62 | |
| 63 | /// Resets the cursor to the beginning of the stream. |
| 64 | pub fn rewindrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`]rewind().(&mut self) { |
| 65 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor. = 0; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | impl<T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>, 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 Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#<T, C> { |
| 70 | fn readrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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#> { |
| 71 | let data = self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader..datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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().buf.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 result/impl#[`Result<T, E>`][Try]branch().; |
| 72 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor.); |
| 73 | let data = &data[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 dup/Dup#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().; |
| 74 | |
| 75 | 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().(), data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 76 | buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#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().(&data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#amount]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 77 | |
| 78 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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; |
| 79 | |
| 80 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(amount) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl<T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>, 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# + 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#> BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> for Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#<T, C> { |
| 85 | fn bufferrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]buffer().(&self) -> &[u8] { |
| 86 | let data = self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader..bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().(); |
| 87 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor.); |
| 88 | &data[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 dup/Dup#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(). |
| 89 | } |
| 90 | |
| 91 | fn datarust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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#> { |
| 92 | let data = self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader..datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 93 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor.); |
| 94 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&data[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 dup/Dup#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().) |
| 95 | } |
| 96 | |
| 97 | fn consumerust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]consume().(&mut self, amount: usize) -> &[u8] { |
| 98 | let data = self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader..bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().(); |
| 99 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). amount); |
| 100 | let data = &data[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 dup/Dup#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().; |
| 101 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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; |
| 102 | data |
| 103 | } |
| 104 | |
| 105 | fn data_consumerust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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#> { |
| 106 | let data = self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader..datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 107 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor.); |
| 108 | let data = &data[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 dup/Dup#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().; |
| 109 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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().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 core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), amount); |
| 110 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(data) |
| 111 | } |
| 112 | |
| 113 | fn data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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#> { |
| 114 | let data = self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader..data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_hard().(self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 115 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cursor. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). amount); |
| 116 | let data = &data[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 dup/Dup#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().; |
| 117 | self.cursorrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#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; |
| 118 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(data) |
| 119 | } |
| 120 | |
| 121 | fn get_mutrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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>> { |
| 122 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader.) |
| 123 | } |
| 124 | |
| 125 | fn get_refrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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>> { |
| 126 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader.) |
| 127 | } |
| 128 | |
| 129 | fn into_innerrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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 dup/impl#[`Dup<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>> |
| 130 | where Selfrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]: 'b { |
| 131 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.readerrust-analyzer cargo buffered-reader 1.4.1 dup/Dup#reader..into_boxedrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#into_boxed().()) |
| 132 | } |
| 133 | |
| 134 | fn cookie_setrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]cookie_set().(&mut self, cookie: C) -> C { |
| 135 | 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/; |
| 136 | |
| 137 | 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 dup/Dup#cookie., cookie) |
| 138 | } |
| 139 | |
| 140 | fn cookie_refrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]cookie_ref().(&self) -> &C { |
| 141 | &self.cookierust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cookie. |
| 142 | } |
| 143 | |
| 144 | fn cookie_mutrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]cookie_mut().(&mut self) -> &mut C { |
| 145 | &mut self.cookierust-analyzer cargo buffered-reader 1.4.1 dup/Dup#cookie. |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #[cfg(test)] |
| 150 | mod testrust-analyzer cargo buffered-reader 1.4.1 dup/test/ { |
| 151 | use superrust-analyzer cargo buffered-reader 1.4.1 dup/::*; |
| 152 | |
| 153 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 154 | fn buffered_reader_memory_testrust-analyzer cargo buffered-reader 1.4.1 dup/test/buffered_reader_memory_test(). () { |
| 155 | let data = craterust-analyzer cargo buffered-reader 1.4.1 crate/::BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA.; |
| 156 | let reader = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]new().(data); |
| 157 | let mut reader = Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#::newrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, ()>`]new().(reader); |
| 158 | |
| 159 | buffered_reader_test_data_checkrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_test_data_check().(&mut reader); |
| 160 | |
| 161 | let consumed = reader.total_outrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`]total_out().(); |
| 162 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(consumed, data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 163 | |
| 164 | // Since we haven't consumed the inner buffer, this should |
| 165 | // still work. |
| 166 | let mut reader = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(reader).into_innerrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]into_inner().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 167 | |
| 168 | // Try to read consumed + 1 bytes (which shouldn't be |
| 169 | // possible). |
| 170 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(consumed, reader.datarust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]data().(consumed +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().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 171 | |
| 172 | buffered_reader_test_data_checkrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_test_data_check().(&mut reader); |
| 173 | } |
| 174 | |
| 175 | // Test that buffer() returns the same data as data(). |
| 176 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 177 | fn buffer_testrust-analyzer cargo buffered-reader 1.4.1 dup/test/buffer_test().() { |
| 178 | // Test vector. A Dup returns all unconsumed |
| 179 | // data. So, use a relatively small buffer size. |
| 180 | let size = default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().(); |
| 181 | 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); |
| 182 | let mut v = 0u8; |
| 183 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#size { |
| 184 | input.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(v); |
| 185 | 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. { |
| 186 | v = 0; |
| 187 | } else { |
| 188 | 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; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | let 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().); |
| 193 | let mut reader = Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#::newrust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, ()>`]new().(reader); |
| 194 | |
| 195 | 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().() { |
| 196 | let data = reader.datarust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<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().(); |
| 197 | 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().()); |
| 198 | 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 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]buffer().()); |
| 199 | // And, we may as well check to make sure we read the |
| 200 | // right data. |
| 201 | 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().); |
| 202 | |
| 203 | // Consume one byte and see what happens. |
| 204 | reader.consumerust-analyzer cargo buffered-reader 1.4.1 dup/impl#[`Dup<T, C>`][`BufferedReader<C>`]consume().(1); |
| 205 | } |
| 206 | } |
| 207 | } |