Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! A [`BufferedReader`] is a super-powered `Read`er.
2 //!
3 //! Like the [`BufRead`] trait, the [`BufferedReader`] trait has an
4 //! internal buffer that is directly exposed to the user. This design
5 //! enables two performance optimizations. First, the use of an
6 //! internal buffer amortizes system calls. Second, exposing the
7 //! internal buffer allows the user to work with data in place, which
8 //! avoids another copy.
9 //!
10 //! The [`BufRead`] trait, however, has a significant limitation for
11 //! parsers: the user of a [`BufRead`] object can't control the amount
12 //! of buffering. This is essential for being able to conveniently
13 //! work with data in place, and being able to lookahead without
14 //! consuming data. The result is that either the sizing has to be
15 //! handled by the instantiator of the [`BufRead`] object---assuming
16 //! the [`BufRead`] object provides such a mechanism---which is a
17 //! layering violation, or the parser has to fallback to buffering if
18 //! the internal buffer is too small, which eliminates most of the
19 //! advantages of the [`BufRead`] abstraction. The [`BufferedReader`]
20 //! trait addresses this shortcoming by allowing the user to control
21 //! the size of the internal buffer.
22 //!
23 //! The [`BufferedReader`] trait also has some functionality,
24 //! specifically, a generic interface to work with a stack of
25 //! [`BufferedReader`] objects, that simplifies using multiple parsers
26 //! simultaneously. This is helpful when one parser deals with
27 //! framing (e.g., something like [HTTP's chunk transfer encoding]),
28 //! and another decodes the actual objects. It is also useful when
29 //! objects are nested.
30 //!
31 //! # Details
32 //!
33 //! Because the [`BufRead`] trait doesn't provide a mechanism for the
34 //! user to size the internal buffer, a parser can't generally be sure
35 //! that the internal buffer will be large enough to allow it to work
36 //! with all data in place.
37 //!
38 //! Using the standard [`BufRead`] implementation, [`BufReader`], the
39 //! instantiator can set the size of the internal buffer at creation
40 //! time. Unfortunately, this mechanism is ugly, and not always
41 //! adequate. First, the parser is typically not the instantiator.
42 //! Thus, the instantiator needs to know about the implementation
43 //! details of all of the parsers, which turns an implementation
44 //! detail into a cross-cutting concern. Second, when working with
45 //! dynamically sized data, the maximum amount of the data that needs
46 //! to be worked with in place may not be known apriori, or the
47 //! maximum amount may be significantly larger than the typical
48 //! amount. This leads to poorly sized buffers.
49 //!
50 //! Alternatively, the code that uses, but does not instantiate a
51 //! [`BufRead`] object, can be changed to stream the data, or to
52 //! fallback to reading the data into a local buffer if the internal
53 //! buffer is too small. Both of these approaches increase code
54 //! complexity, and the latter approach is contrary to the
55 //! [`BufRead`]'s goal of reducing unnecessary copying.
56 //!
57 //! The [`BufferedReader`] trait solves this problem by allowing the
58 //! user to dynamically (i.e., at read time, not open time) ensure
59 //! that the internal buffer has a certain amount of data.
60 //!
61 //! The ability to control the size of the internal buffer is also
62 //! essential to straightforward support for speculative lookahead.
63 //! The reason that speculative lookahead with a [`BufRead`] object is
64 //! difficult is that speculative lookahead is /speculative/, i.e., if
65 //! the parser backtracks, the data that was read must not be
66 //! consumed. Using a [`BufRead`] object, this is not possible if the
67 //! amount of lookahead is larger than the internal buffer. That is,
68 //! if the amount of lookahead data is larger than the [`BufRead`]'s
69 //! internal buffer, the parser first has to [`std::io::BufRead::consume`] some
70 //! data to be able to examine more data. But, if the parser then
71 //! decides to backtrack, it has no way to return the unused data to
72 //! the [`BufRead`] object. This forces the parser to manage a buffer
73 //! of read, but unconsumed data, which significantly complicates the
74 //! code.
75 //!
76 //! The [`BufferedReader`] trait also simplifies working with a stack of
77 //! [`BufferedReader`]s in two ways. First, the [`BufferedReader`] trait
78 //! provides *generic* methods to access the underlying
79 //! [`BufferedReader`]. Thus, even when dealing with a trait object, it
80 //! is still possible to recover the underlying [`BufferedReader`].
81 //! Second, the [`BufferedReader`] provides a mechanism to associate
82 //! generic state with each [`BufferedReader`] via a cookie. Although
83 //! it is possible to realize this functionality using a custom trait
84 //! that extends the [`BufferedReader`] trait and wraps existing
85 //! [`BufferedReader`] implementations, this approach eliminates a lot
86 //! of error-prone, boilerplate code.
87 //!
88 //! # Examples
89 //!
90 //! The following examples show not only how to use a
91 //! [`BufferedReader`], but also better illustrate the aforementioned
92 //! limitations of a [`BufRead`]er.
93 //!
94 //! Consider a file consisting of a sequence of objects, which are
95 //! laid out as follows. Each object has a two byte header that
96 //! indicates the object's size in bytes. The object immediately
97 //! follows the header. Thus, if we had two objects: "foobar" and
98 //! "xyzzy", in that order, the file would look like this:
99 //!
100 //! ```text
101 //! 0 6 f o o b a r 0 5 x y z z y
102 //! ```
103 //!
104 //! Here's how we might parse this type of file using a
105 //! [`BufferedReader`]:
106 //!
107 //! ```
108 //! use buffered_reader;
109 //! use buffered_reader::BufferedReader;
110 //!
111 //! fn parse_object(content: &[u8]) {
112 //! // Parse the object.
113 //! # let _ = content;
114 //! }
115 //!
116 //! # f(); fn f() -> Result<(), std::io::Error> {
117 //! # const FILENAME : &str = "/dev/null";
118 //! let mut br = buffered_reader::File::open(FILENAME)?;
119 //!
120 //! // While we haven't reached EOF (i.e., we can read at
121 //! // least one byte).
122 //! while br.data(1)?.len() > 0 {
123 //! // Get the object's length.
124 //! let len = br.read_be_u16()? as usize;
125 //! // Get the object's content.
126 //! let content = br.data_consume_hard(len)?;
127 //!
128 //! // Parse the actual object using a real parser. Recall:
129 //! // `data_hard`() may return more than the requested amount (but
130 //! // it will never return less).
131 //! parse_object(&content[..len]);
132 //! }
133 //! # Ok(()) }
134 //! ```
135 //!
136 //! Note that `content` is actually a pointer to the
137 //! [`BufferedReader`]'s internal buffer. Thus, getting some data
138 //! doesn't require copying the data into a local buffer, which is
139 //! often discarded immediately after the data is parsed.
140 //!
141 //! Further, [`BufferedReader::data`] (and the other related functions) are guaranteed
142 //! to return at least the requested amount of data. There are two
143 //! exceptions: if an error occurs, or the end of the file is reached.
144 //! Thus, only the cases that actually need to be handled by the user
145 //! are actually exposed; there is no need to call something like
146 //! [`std::io::Read::read`] in a loop to ensure the whole object is available.
147 //!
148 //! Because reading is separate from consuming data, it is possible to
149 //! get a chunk of data, inspect it, and then consume only what is
150 //! needed. As mentioned above, this is only possible with a
151 //! [`BufRead`] object if the internal buffer happens to be large
152 //! enough. Using a [`BufferedReader`], this is always possible,
153 //! assuming the data fits in memory.
154 //!
155 //! In our example, we actually have two parsers: one that deals with
156 //! the framing, and one for the actual objects. The above code
157 //! buffers the objects in their entirety, and then passes a slice
158 //! containing the object to the object parser. If the object parser
159 //! also worked with a [`BufferedReader`] object, then less buffering
160 //! will usually be needed, and the two parsers could run
161 //! simultaneously. This is particularly useful when the framing is
162 //! more complicated like [HTTP's chunk transfer encoding]. Then,
163 //! when the object parser reads data, the frame parser is invoked
164 //! lazily. This is done by implementing the [`BufferedReader`] trait
165 //! for the framing parser, and stacking the [`BufferedReader`]s.
166 //!
167 //! For our next example, we rewrite the previous code assuming that
168 //! the object parser reads from a [`BufferedReader`] object. Since the
169 //! framing parser is really just a limit on the object's size, we
170 //! don't need to implement a special [`BufferedReader`], but can use a
171 //! [`Limitor`] to impose an upper limit on the amount
172 //! that it can read. After the object parser has finished, we drain
173 //! the object reader. This pattern is particularly helpful when
174 //! individual objects that contain errors should be skipped.
175 //!
176 //! ```
177 //! use buffered_reader;
178 //! use buffered_reader::BufferedReader;
179 //!
180 //! fn parse_object<R: BufferedReader<()>>(br: &mut R) {
181 //! // Parse the object.
182 //! # let _ = br;
183 //! }
184 //!
185 //! # f(); fn f() -> Result<(), std::io::Error> {
186 //! # const FILENAME : &str = "/dev/null";
187 //! let mut br : Box<dyn BufferedReader<()>>
188 //! = Box::new(buffered_reader::File::open(FILENAME)?);
189 //!
190 //! // While we haven't reached EOF (i.e., we can read at
191 //! // least one byte).
192 //! while br.data(1)?.len() > 0 {
193 //! // Get the object's length.
194 //! let len = br.read_be_u16()? as u64;
195 //!
196 //! // Set up a limit.
197 //! br = Box::new(buffered_reader::Limitor::new(br, len));
198 //!
199 //! // Parse the actual object using a real parser.
200 //! parse_object(&mut br);
201 //!
202 //! // If the parser didn't consume the whole object, e.g., due to
203 //! // a parse error, drop the rest.
204 //! br.drop_eof();
205 //!
206 //! // Recover the framing parser's `BufferedReader`.
207 //! br = br.into_inner().unwrap();
208 //! }
209 //! # Ok(()) }
210 //! ```
211 //!
212 //! Of particular note is the generic functionality for dealing with
213 //! stacked [`BufferedReader`]s: the [`BufferedReader::into_inner`] method is not bound
214 //! to the implementation, which is often not be available due to type
215 //! erasure, but is provided by the trait.
216 //!
217 //! In addition to utility [`BufferedReader`]s like the
218 //! [`Limitor`], this crate also includes a few
219 //! general-purpose parsers, like the `Zlib`
220 //! decompressor.
221 //!
222 //! [`BufRead`]: std::io::BufRead
223 //! [`BufReader`]: std::io::BufReader
224 //! [HTTP's chunk transfer encoding]: https://en.wikipedia.org/wiki/Chunked_transfer_encoding
225
226 #![doc(html_favicon_url = "https://docs.sequoia-pgp.org/favicon.png")]
227 #![doc(html_logo_url = "https://docs.sequoia-pgp.org/logo.svg")]
228 #![warn(missing_docs)]
229
230 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/;
231 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#};
232 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/;
233 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/;
234 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#;
235
236 #[macro_use]
237 mod macrosrust-analyzer cargo buffered-reader 1.4.1 macros/;
238
239 mod genericrust-analyzer cargo buffered-reader 1.4.1 generic/;
240 mod memoryrust-analyzer cargo buffered-reader 1.4.1 memory/;
241 mod limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/;
242 mod reserverust-analyzer cargo buffered-reader 1.4.1 reserve/;
243 mod duprust-analyzer cargo buffered-reader 1.4.1 dup/;
244 mod eofrust-analyzer cargo buffered-reader 1.4.1 eof/;
245 mod adapterrust-analyzer cargo buffered-reader 1.4.1 adapter/;
246 #[cfg(feature = "compression-deflate")]
247 mod decompress_deflaterust-analyzer cargo buffered-reader 1.4.1 decompress_deflate/;
248 #[cfg(feature = "compression-bzip2")]
249 mod decompress_bzip2rust-analyzer cargo buffered-reader 1.4.1 decompress_bzip2/;
250
251 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::genericrust-analyzer cargo buffered-reader 1.4.1 generic/::Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#;
252 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::memoryrust-analyzer cargo buffered-reader 1.4.1 memory/::Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#;
253 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/::Limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/Limitor#;
254 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::reserverust-analyzer cargo buffered-reader 1.4.1 reserve/::Reserverust-analyzer cargo buffered-reader 1.4.1 reserve/Reserve#;
255 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::duprust-analyzer cargo buffered-reader 1.4.1 dup/::Duprust-analyzer cargo buffered-reader 1.4.1 dup/Dup#;
256 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::eofrust-analyzer cargo buffered-reader 1.4.1 eof/::EOFrust-analyzer cargo buffered-reader 1.4.1 eof/EOF#;
257 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::adapterrust-analyzer cargo buffered-reader 1.4.1 adapter/::Adapterrust-analyzer cargo buffered-reader 1.4.1 adapter/Adapter#;
258 #[cfg(feature = "compression-deflate")]
259 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::decompress_deflaterust-analyzer cargo buffered-reader 1.4.1 decompress_deflate/::Deflaterust-analyzer cargo buffered-reader 1.4.1 decompress_deflate/Deflate#;
260 #[cfg(feature = "compression-deflate")]
261 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::decompress_deflaterust-analyzer cargo buffered-reader 1.4.1 decompress_deflate/::Zlibrust-analyzer cargo buffered-reader 1.4.1 decompress_deflate/Zlib#;
262 #[cfg(feature = "compression-bzip2")]
263 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::decompress_bzip2rust-analyzer cargo buffered-reader 1.4.1 decompress_bzip2/::Bziprust-analyzer cargo buffered-reader 1.4.1 decompress_bzip2/Bzip#;
264
265 // Common error type for file operations.
266 mod file_errorrust-analyzer cargo buffered-reader 1.4.1 file_error/;
267
268 // These are the different File implementations. We
269 // include the modules unconditionally, so that we catch bitrot early.
270 #[allow(dead_code)]
271 mod file_genericrust-analyzer cargo buffered-reader 1.4.1 file_generic/;
272 #[allow(dead_code)]
273 #[cfg(unix)]
274 mod file_unixrust-analyzer cargo buffered-reader 1.4.1 file_unix/;
275
276 // Then, we select the appropriate version to re-export.
277 #[cfg(not(unix))]
278 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::file_genericrust-analyzer cargo buffered-reader 1.4.1 file_generic/::Filerust-analyzer cargo buffered-reader 1.4.1 file_generic/File#;
279 #[cfg(unix)]
280 pub use selfrust-analyzer cargo buffered-reader 1.4.1 crate/::file_unixrust-analyzer cargo buffered-reader 1.4.1 file_unix/::Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#;
281
282 /// The default buffer size.
283 ///
284 /// This is configurable by the SEQUOIA_BUFFERED_READER_BUFFER
285 /// environment variable.
286 fn default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().() -> usize {
287 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#;
288
289 static DEFAULT_BUF_SIZErust-analyzer cargo buffered-reader 1.4.1 DEFAULT_BUF_SIZE.: OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#<usize> = OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]new().();
290 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().DEFAULT_BUF_SIZErust-analyzer cargo buffered-reader 1.4.1 DEFAULT_BUF_SIZE..get_or_initrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]get_or_init().(|| {
291 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().;
292 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
293
294 let default = 32 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().1024;
295
296 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(size) = var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().("SEQUOIA_BUFFERED_READER_BUFFER") {
297 size.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()
298 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|s| {
299 match FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize][FromStr]from_str().(s) {
300 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s),
301 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
302 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Unable to parse the value of \
303 'SEQUOIA_BUFFERED_READER_BUFFER'; \
304 falling back to the default buffer \
305 size ({}): {}",
306 err, default);
307 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
308 }
309 }
310 })
311 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(default)
312 } else {
313 default
314 }
315 })
316 }
317
318 // On debug builds, Vec<u8>::truncate is very, very slow. For
319 // instance, running the decrypt_test_stream test takes 51 seconds on
320 // my (Neal's) computer using Vec<u8>::truncate and <0.1 seconds using
321 // `unsafe { v.set_len(len); }`.
322 //
323 // The issue is that the compiler calls drop on every element that is
324 // dropped, even though a u8 doesn't have a drop implementation. The
325 // compiler optimizes this away at high optimization levels, but those
326 // levels make debugging harder.
327 fn vec_truncaterust-analyzer cargo buffered-reader 1.4.1 vec_truncate().(v: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, len: usize) {
328 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(debug_assertions) {
329 if len 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().v.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
330 unsafe { v.set_lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]set_len().(len); }
331 }
332 } else {
333 v.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(len);
334 }
335 }
336
337 /// Like `Vec<u8>::resize`, but fast in debug builds.
338 fn vec_resizerust-analyzer cargo buffered-reader 1.4.1 vec_resize().(v: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, new_size: usize) {
339 if v.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 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().new_size {
340 v.resizerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]resize().(new_size, 0);
341 } else {
342 vec_truncaterust-analyzer cargo buffered-reader 1.4.1 vec_truncate().(v, new_size);
343 }
344 }
345
346 /// The generic `BufferReader` interface.
347 pub trait BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> : 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# + 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# + 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# + 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#
348 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# + 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#
349 {
350 /// Returns a reference to the internal buffer.
351 ///
352 /// Note: this returns the same data as `self.data(0)`, but it
353 /// does so without mutably borrowing self:
354 ///
355 /// ```
356 /// # f(); fn f() -> Result<(), std::io::Error> {
357 /// use buffered_reader;
358 /// use buffered_reader::BufferedReader;
359 ///
360 /// let mut br = buffered_reader::Memory::new(&b"0123456789"[..]);
361 ///
362 /// let first = br.data(10)?.len();
363 /// let second = br.buffer().len();
364 /// // `buffer` must return exactly what `data` returned.
365 /// assert_eq!(first, second);
366 /// # Ok(()) }
367 /// ```
368 fn bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().(&self) -> &[u8];
369
370 /// Ensures that the internal buffer has at least `amount` bytes
371 /// of data, and returns it.
372 ///
373 /// If the internal buffer contains less than `amount` bytes of
374 /// data, the internal buffer is first filled.
375 ///
376 /// The returned slice will have *at least* `amount` bytes unless
377 /// EOF has been reached or an error occurs, in which case the
378 /// returned slice will contain the rest of the file.
379 ///
380 /// Errors are returned only when the internal buffer is empty.
381 ///
382 /// This function does not advance the cursor. To advance the
383 /// cursor, use [`BufferedReader::consume`].
384 ///
385 /// Note: If the internal buffer already contains at least
386 /// `amount` bytes of data, then [`BufferedReader`]
387 /// implementations are guaranteed to simply return the internal
388 /// buffer. As such, multiple calls to [`BufferedReader::data`]
389 /// for the same `amount` will return the same slice.
390 ///
391 /// Further, [`BufferedReader`] implementations are guaranteed to
392 /// not shrink the internal buffer. Thus, once some data has been
393 /// returned, it will always be returned until it is consumed.
394 /// As such, the following must hold:
395 ///
396 /// If [`BufferedReader`] receives `EINTR` when `read`ing, it will
397 /// automatically retry reading.
398 ///
399 /// ```
400 /// # f(); fn f() -> Result<(), std::io::Error> {
401 /// use buffered_reader;
402 /// use buffered_reader::BufferedReader;
403 ///
404 /// let mut br = buffered_reader::Memory::new(&b"0123456789"[..]);
405 ///
406 /// let first = br.data(10)?.len();
407 /// let second = br.data(5)?.len();
408 /// // Even though less data is requested, the second call must
409 /// // return the same slice as the first call.
410 /// assert_eq!(first, second);
411 /// # Ok(()) }
412 /// ```
413 fn datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#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#>;
414
415 /// Like [`BufferedReader::data`], but returns an error if there is not at least
416 /// `amount` bytes available.
417 ///
418 /// [`BufferedReader::data_hard`] is a variant of [`BufferedReader::data`] that returns at least
419 /// `amount` bytes of data or an error. Thus, unlike [`BufferedReader::data`],
420 /// which will return less than `amount` bytes of data if EOF is
421 /// encountered, [`BufferedReader::data_hard`] returns an error, specifically,
422 /// `io::ErrorKind::UnexpectedEof`.
423 ///
424 /// # Examples
425 ///
426 /// ```
427 /// # f(); fn f() -> Result<(), std::io::Error> {
428 /// use buffered_reader;
429 /// use buffered_reader::BufferedReader;
430 ///
431 /// let mut br = buffered_reader::Memory::new(&b"0123456789"[..]);
432 ///
433 /// // Trying to read more than there is available results in an error.
434 /// assert!(br.data_hard(20).is_err());
435 /// // Whereas with data(), everything through EOF is returned.
436 /// assert_eq!(br.data(20)?.len(), 10);
437 /// # Ok(()) }
438 /// ```
439 fn data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#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#> {
440 let result = self.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(amount);
441 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buffer) = result {
442 if 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 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 {
443 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#,
444 "unexpected EOF"));
445 }
446 }
447 result
448 }
449
450 /// Returns all of the data until EOF. Like [`BufferedReader::data`], this does not
451 /// actually consume the data that is read.
452 ///
453 /// In general, you shouldn't use this function as it can cause an
454 /// enormous amount of buffering. But, if you know that the
455 /// amount of data is limited, this is acceptable.
456 ///
457 /// # Examples
458 ///
459 /// ```
460 /// # f(); fn f() -> Result<(), std::io::Error> {
461 /// use buffered_reader;
462 /// use buffered_reader::BufferedReader;
463 ///
464 /// const AMOUNT : usize = 100 * 1024 * 1024;
465 /// let buffer = vec![0u8; AMOUNT];
466 /// let mut br = buffered_reader::Generic::new(&buffer[..], None);
467 ///
468 /// // Normally, only a small amount will be buffered.
469 /// assert!(br.data(10)?.len() <= AMOUNT);
470 ///
471 /// // `data_eof` buffers everything.
472 /// assert_eq!(br.data_eof()?.len(), AMOUNT);
473 ///
474 /// // Now that everything is buffered, buffer(), data(), and
475 /// // data_hard() will also return everything.
476 /// assert_eq!(br.buffer().len(), AMOUNT);
477 /// assert_eq!(br.data(10)?.len(), AMOUNT);
478 /// assert_eq!(br.data_hard(10)?.len(), AMOUNT);
479 /// # Ok(()) }
480 /// ```
481 fn data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().(&mut self) -> 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#> {
482 // Don't just read std::usize::MAX bytes at once. The
483 // implementation might try to actually allocate a buffer that
484 // large! Instead, try with increasingly larger buffers until
485 // the read is (strictly) shorter than the specified size.
486 let mut s = default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().();
487 // We will break the loop eventually, because self.data(s)
488 // must return a slice shorter than std::usize::MAX.
489 loop {
490 match self.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(s) {
491 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buffer) => {
492 if 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 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().s {
493 // We really want to do
494 //
495 // return Ok(buffer);
496 //
497 // But, the borrower checker won't let us:
498 //
499 // error[E0499]: cannot borrow `*self` as
500 // mutable more than once at a time.
501 //
502 // Instead, we break out of the loop, and then
503 // call self.buffer().
504 s = buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
505 break;
506 } else {
507 s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign().*=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`MulAssign<Self>`]mul_assign().2;
508 }
509 }
510 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) =>
511 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err),
512 }
513 }
514
515 let buffer = self.bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().();
516 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), s);
517 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buffer)
518 }
519
520 /// Consumes some of the data.
521 ///
522 /// This advances the internal cursor by `amount`. It is an error
523 /// to call this function to consume data that hasn't been
524 /// returned by [`BufferedReader::data`] or a related function.
525 ///
526 /// Note: It is safe to call this function to consume more data
527 /// than requested in a previous call to [`BufferedReader::data`], but only if
528 /// [`BufferedReader::data`] also returned that data.
529 ///
530 /// This function returns the internal buffer *including* the
531 /// consumed data. Thus, the [`BufferedReader`] implementation must
532 /// continue to buffer the consumed data until the reference goes
533 /// out of scope.
534 ///
535 /// # Examples
536 ///
537 /// ```
538 /// # f(); fn f() -> Result<(), std::io::Error> {
539 /// use buffered_reader;
540 /// use buffered_reader::BufferedReader;
541 ///
542 /// const AMOUNT : usize = 100 * 1024 * 1024;
543 /// let buffer = vec![0u8; AMOUNT];
544 /// let mut br = buffered_reader::Generic::new(&buffer[..], None);
545 ///
546 /// let amount = {
547 /// // We want at least 1024 bytes, but we'll be happy with
548 /// // more or less.
549 /// let buffer = br.data(1024)?;
550 /// // Parse the data or something.
551 /// let used = buffer.len();
552 /// used
553 /// };
554 /// let buffer = br.consume(amount);
555 /// # Ok(()) }
556 /// ```
557 fn consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(&mut self, amount: usize) -> &[u8];
558
559 /// A convenience function that combines [`BufferedReader::data`] and [`BufferedReader::consume`].
560 ///
561 /// If less than `amount` bytes are available, this function
562 /// consumes what is available.
563 ///
564 /// Note: Due to lifetime issues, it is not possible to call
565 /// [`BufferedReader::data`], work with the returned buffer, and then call
566 /// [`BufferedReader::consume`] in the same scope, because both [`BufferedReader::data`] and
567 /// [`BufferedReader::consume`] take a mutable reference to the [`BufferedReader`].
568 /// This function makes this common pattern easier.
569 ///
570 /// # Examples
571 ///
572 /// ```
573 /// # f(); fn f() -> Result<(), std::io::Error> {
574 /// use buffered_reader;
575 /// use buffered_reader::BufferedReader;
576 ///
577 /// let orig = b"0123456789";
578 /// let mut br = buffered_reader::Memory::new(&orig[..]);
579 ///
580 /// // We need a new scope for each call to [`BufferedReader::data_consume`], because
581 /// // the `buffer` reference locks `br`.
582 /// {
583 /// let buffer = br.data_consume(3)?;
584 /// assert_eq!(buffer, &orig[..buffer.len()]);
585 /// }
586 ///
587 /// // Note that the cursor has advanced.
588 /// {
589 /// let buffer = br.data_consume(3)?;
590 /// assert_eq!(buffer, &orig[3..3 + buffer.len()]);
591 /// }
592 ///
593 /// // Like [`BufferedReader::data`], [`BufferedReader::data_consume`] may return and consume less
594 /// // than requested if there is no more data available.
595 /// {
596 /// let buffer = br.data_consume(10)?;
597 /// assert_eq!(buffer, &orig[6..6 + buffer.len()]);
598 /// }
599 ///
600 /// {
601 /// let buffer = br.data_consume(10)?;
602 /// assert_eq!(buffer.len(), 0);
603 /// }
604 /// # Ok(()) }
605 /// ```
606 fn data_consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume().(&mut self, amount: usize)
607 -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], 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#> {
608 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.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(amount)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
609
610 let buffer = self.consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(amount);
611 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= amount);
612 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buffer)
613 }
614
615 /// A convenience function that effectively combines [`BufferedReader::data_hard`]
616 /// and [`BufferedReader::consume`].
617 ///
618 /// This function is identical to [`BufferedReader::data_consume`], but internally
619 /// uses [`BufferedReader::data_hard`] instead of [`BufferedReader::data`].
620 fn data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(&mut self, amount: usize)
621 -> 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#>
622 {
623 let len = self.data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_hard().(amount)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
624 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(len >= amount);
625
626 let buffer = self.consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(amount);
627 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= amount);
628 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buffer)
629 }
630
631 /// Checks whether the end of the stream is reached.
632 fn eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#eof().(&mut self) -> bool {
633 self.data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_hard().(1).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()
634 }
635
636 /// Checks whether this reader is consummated.
637 ///
638 /// For most readers, this function will return true once the end
639 /// of the stream is reached. However, some readers are concerned
640 /// with packet framing (e.g. the [`Limitor`]). Those readers
641 /// consider themselves consummated if the amount of data
642 /// indicated by the packet frame is consumed.
643 ///
644 /// This allows us to detect truncation. A packet is truncated,
645 /// iff the end of the stream is reached, but the reader is not
646 /// consummated.
647 ///
648 fn consummatedrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consummated().(&mut self) -> bool {
649 self.eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#eof().()
650 }
651
652 /// A convenience function for reading a 16-bit unsigned integer
653 /// in big endian format.
654 fn read_be_u16rust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_be_u16().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u16, 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#> {
655 let input = self.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(2)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
656 // input holds at least 2 bytes, so this cannot fail.
657 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(u16::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]from_be_bytes().(input[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#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()))
658 }
659
660 /// A convenience function for reading a 32-bit unsigned integer
661 /// in big endian format.
662 fn read_be_u32rust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_be_u32().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u32, 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#> {
663 let input = self.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(4)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
664 // input holds at least 4 bytes, so this cannot fail.
665 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(u32::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_be_bytes().(input[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#4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()))
666 }
667
668 /// Reads until either `terminal` is encountered or EOF.
669 ///
670 /// Returns either a `&[u8]` terminating in `terminal` or the rest
671 /// of the data, if EOF was encountered.
672 ///
673 /// Note: this function does *not* consume the data.
674 ///
675 /// # Examples
676 ///
677 /// ```
678 /// # f(); fn f() -> Result<(), std::io::Error> {
679 /// use buffered_reader;
680 /// use buffered_reader::BufferedReader;
681 ///
682 /// let orig = b"0123456789";
683 /// let mut br = buffered_reader::Memory::new(&orig[..]);
684 ///
685 /// {
686 /// let s = br.read_to(b'3')?;
687 /// assert_eq!(s, b"0123");
688 /// }
689 ///
690 /// // [`BufferedReader::read_to`] doesn't consume the data.
691 /// {
692 /// let s = br.read_to(b'5')?;
693 /// assert_eq!(s, b"012345");
694 /// }
695 ///
696 /// // Even if there is more data in the internal buffer, only
697 /// // the data through the match is returned.
698 /// {
699 /// let s = br.read_to(b'1')?;
700 /// assert_eq!(s, b"01");
701 /// }
702 ///
703 /// // If the terminal is not found, everything is returned...
704 /// {
705 /// let s = br.read_to(b'A')?;
706 /// assert_eq!(s, orig);
707 /// }
708 ///
709 /// // If we consume some data, the search starts at the cursor,
710 /// // not the beginning of the file.
711 /// br.consume(3);
712 ///
713 /// {
714 /// let s = br.read_to(b'5')?;
715 /// assert_eq!(s, b"345");
716 /// }
717 /// # Ok(()) }
718 /// ```
719 fn read_torust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_to().(&mut self, terminal: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], 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#> {
720 let mut n = 128;
721 let len;
722
723 loop {
724 let data = self.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(n)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
725
726 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(newline)
727 = data.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|c| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c 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().terminal)
728 {
729 len = newline 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;
730 break;
731 } else if data.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 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().n {
732 // EOF.
733 len = data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
734 break;
735 } else {
736 // Read more data.
737 n = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(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().n, data.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][`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().1024);
738 }
739 }
740
741 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&self.bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().()[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#len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)
742 }
743
744 /// Discards the input until one of the bytes in terminals is
745 /// encountered.
746 ///
747 /// The matching byte is not discarded.
748 ///
749 /// Returns the number of bytes discarded.
750 ///
751 /// The end of file is considered a match.
752 ///
753 /// `terminals` must be sorted.
754 fn drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(&mut self, terminals: &[u8])
755 -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, 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#>
756 {
757 // Make sure terminals is sorted.
758 for t in terminals.windowsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]windows().(2) {
759 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). <= t[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
760 }
761
762 let buf_size = default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().();
763 let mut total = 0;
764 let position = 'outer: loop {
765 let len = {
766 // Try self.buffer. Only if it is empty, use
767 // self.data.
768 let buffer = if self.bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
769 self.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(buf_size)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
770 } else {
771 self.bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().()
772 };
773
774 if buffer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
775 break 'outer 0;
776 }
777
778 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(position) = buffer.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(
779 |c| terminals.binary_searchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]binary_search().(c).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().())
780 {
781 break 'outer position;
782 }
783
784 buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()
785 };
786
787 self.consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(len);
788 total 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().len;
789 };
790
791 self.consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(position);
792 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(total 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().position)
793 }
794
795 /// Discards the input until one of the bytes in `terminals` is
796 /// encountered.
797 ///
798 /// The matching byte is also discarded.
799 ///
800 /// Returns the terminal byte and the number of bytes discarded.
801 ///
802 /// If match_eof is true, then the end of file is considered a
803 /// match. Otherwise, if the end of file is encountered, an error
804 /// is returned.
805 ///
806 /// `terminals` must be sorted.
807 fn drop_throughrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_through().(&mut self, terminals: &[u8], match_eof: bool)
808 -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>, usize), 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#>
809 {
810 let dropped = self.drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(terminals)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
811 match self.data_consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume().(1) {
812 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#([]) if match_eof => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, dropped)),
813 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#([]) => 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")),
814 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rest) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().), dropped 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)),
815 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err),
816 }
817 }
818
819 /// Like [`BufferedReader::data_consume_hard`], but returns the data in a
820 /// caller-owned buffer.
821 ///
822 /// [`BufferedReader`] implementations may optimize this to avoid a
823 /// copy by directly returning the internal buffer.
824 fn stealrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#steal().(&mut self, amount: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, 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#> {
825 let mut data = self.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(amount)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
826 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().() >= amount);
827 if data.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 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 {
828 data = &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().;
829 }
830 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(data.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().())
831 }
832
833 /// Like [`BufferedReader::steal`], but instead of stealing a fixed number of
834 /// bytes, steals all of the data until the end of file.
835 fn steal_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#steal_eof().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, 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#> {
836 let len = self.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
837 let data = self.stealrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#steal().(len)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
838 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(data)
839 }
840
841 /// Like [`BufferedReader::steal_eof`], but instead of returning the data, the
842 /// data is discarded.
843 ///
844 /// On success, returns whether any data (i.e., at least one byte)
845 /// was discarded.
846 ///
847 /// Note: whereas [`BufferedReader::steal_eof`] needs to buffer all of the data,
848 /// this function reads the data a chunk at a time, and then
849 /// discards it. A consequence of this is that an error may occur
850 /// after we have consumed some of the data.
851 fn drop_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_eof().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, 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#> {
852 let buf_size = default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().();
853 let mut at_least_one_byte = false;
854 loop {
855 let n = self.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(buf_size)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
856 at_least_one_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().n 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;
857 self.consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(n);
858 if n 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().buf_size {
859 // EOF.
860 break;
861 }
862 }
863
864 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(at_least_one_byte)
865 }
866
867 /// Copies data to the given writer returning the copied amount.
868 ///
869 /// This is like using [`std::io::copy`], but more efficient as it
870 /// avoids an extra copy, and it will try to copy all the data the
871 /// reader has already buffered.
872 ///
873 /// On success, returns the amount of data (in bytes) that has
874 /// been copied.
875 ///
876 /// Note: this function reads and copies the data a chunk at a
877 /// time. A consequence of this is that an error may occur after
878 /// we have consumed some of the data.
879 fn copyrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#copy().(&mut self, sink: &mut dyn iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> 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#<u64> {
880 let buf_size = default_buf_sizerust-analyzer cargo buffered-reader 1.4.1 default_buf_size().();
881 let mut total = 0;
882 loop {
883 let data = self.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(buf_size)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
884 sink.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
885
886 let n = data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
887 total rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().n as u64;
888 self.consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(n);
889 if n 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().buf_size {
890 // EOF.
891 break;
892 }
893 }
894
895 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(total)
896 }
897
898 /// A helpful debugging aid to pretty print a Buffered Reader stack.
899 ///
900 /// Uses the Buffered Readers' `fmt::Display` implementations.
901 fn dumprust-analyzer cargo buffered-reader 1.4.1 BufferedReader#dump().(&self, sink: &mut dyn 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/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
902 where Self: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#
903 {
904 let mut i = 1;
905 let mut reader: 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>> = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self);
906 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r) = reader {
907 {
908 let cookie = r.cookie_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_ref().();
909 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(sink, " {}. {}, {:?}", i, r, cookie)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
910 }
911 reader = r.get_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#get_ref().();
912 i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
913 }
914 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
915 }
916
917 /// Boxes the reader.
918 fn into_boxedrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#into_boxed().<'a>(self) -> 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> + 'a>
919 where Self: 'a + Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#
920 {
921 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().(self)
922 }
923
924 /// Boxes the reader.
925 #[deprecated(note = "Use into_boxed")]
926 fn as_boxedrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#as_boxed().<'a>(self) -> 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> + 'a>
927 where Self: 'a + Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#
928 {
929 self.into_boxedrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#into_boxed().()
930 }
931
932 /// Returns the underlying reader, if any.
933 ///
934 /// To allow this to work with [`BufferedReader`] traits, it is
935 /// necessary for `Self` to be boxed.
936 ///
937 /// This can lead to the following unusual code:
938 ///
939 /// ```text
940 /// let inner = Box::new(br).into_inner();
941 /// ```
942 ///
943 /// Note: if `Self` is not actually owned, e.g., you passed a
944 /// reference, then this returns `None` as it is not possible to
945 /// consume the outer buffered reader. Consider:
946 ///
947 /// ```
948 /// # use buffered_reader::BufferedReader;
949 /// # use buffered_reader::Limitor;
950 /// # use buffered_reader::Memory;
951 /// #
952 /// # const DATA : &[u8] = b"01234567890123456789suffix";
953 /// #
954 /// let mut mem = Memory::new(DATA);
955 /// let mut limitor = Limitor::new(mem, 20);
956 /// let mut br = Box::new(&mut limitor);
957 /// // br doesn't owned limitor, so it can't consume it.
958 /// assert!(matches!(br.into_inner(), None));
959 ///
960 /// let mut mem = Memory::new(DATA);
961 /// let mut limitor = Limitor::new(mem, 20);
962 /// let mut br = Box::new(limitor);
963 /// assert!(matches!(br.into_inner(), Some(_)));
964 fn into_innerrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#into_inner().<'a>(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Self>) -> 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> + 'a>>
965 where Self: 'a;
966
967 /// Returns a mutable reference to the inner [`BufferedReader`], if
968 /// any.
969 ///
970 /// It is a very bad idea to read any data from the inner
971 /// [`BufferedReader`], because this [`BufferedReader`] may have some
972 /// data buffered. However, this function can be useful to get
973 /// the cookie.
974 fn get_mutrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#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>>;
975
976 /// Returns a reference to the inner [`BufferedReader`], if any.
977 fn get_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#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>>;
978
979 /// Sets the [`BufferedReader`]'s cookie and returns the old value.
980 fn cookie_setrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_set().(&mut self, cookie: C) -> C;
981
982 /// Returns a reference to the [`BufferedReader`]'s cookie.
983 fn cookie_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_ref().(&self) -> &C;
984
985 /// Returns a mutable reference to the [`BufferedReader`]'s cookie.
986 fn cookie_mutrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_mut().(&mut self) -> &mut C;
987 }
988
989 /// A generic implementation of `std::io::Read::read` appropriate for
990 /// any [`BufferedReader`] implementation.
991 ///
992 /// This function implements the `std::io::Read::read` method in terms
993 /// of the `data_consume` method. We can't use the `io::std::Read`
994 /// interface, because the [`BufferedReader`] may have buffered some
995 /// data internally (in which case a read will not return the buffered
996 /// data, but the following data).
997 ///
998 /// This implementation is generic. When deriving a [`BufferedReader`],
999 /// you can include the following:
1000 ///
1001 /// ```text
1002 /// impl<'a, T: BufferedReader> std::io::Read for XXX<'a, T> {
1003 /// fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
1004 /// return buffered_reader_generic_read_impl(self, buf);
1005 /// }
1006 /// }
1007 /// ```
1008 ///
1009 /// It would be nice if we could do:
1010 ///
1011 /// ```text
1012 /// impl <T: BufferedReader> std::io::Read for T { ... }
1013 /// ```
1014 ///
1015 /// but, alas, Rust doesn't like that ("error\[E0119\]: conflicting
1016 /// implementations of trait `std::io::Read` for type `&mut _`").
1017 pub fn buffered_reader_generic_read_implrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_generic_read_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#>
1018 (bio: &mut T, 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#> {
1019 bio
1020 .data_consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume().(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())
1021 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|inner| {
1022 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().(), inner.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
1023 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().(&inner[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().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/Index#index().);
1024 amount
1025 })
1026 }
1027
1028 /// Make a `Box<BufferedReader>` look like a BufferedReader.
1029 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 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> + 'a> {
1030 fn bufferrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]buffer().(&self) -> &[u8] {
1031 return self.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsRef<T>`]as_ref().().bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().();
1032 }
1033
1034 fn datarust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`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#> {
1035 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(amount);
1036 }
1037
1038 fn data_hardrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`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#> {
1039 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_hard().(amount);
1040 }
1041
1042 fn data_eofrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]data_eof().(&mut self) -> 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#> {
1043 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().();
1044 }
1045
1046 fn consumerust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]consume().(&mut self, amount: usize) -> &[u8] {
1047 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(amount);
1048 }
1049
1050 fn data_consumerust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]data_consume().(&mut self, amount: usize)
1051 -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], 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#> {
1052 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().data_consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume().(amount);
1053 }
1054
1055 fn data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`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#> {
1056 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(amount);
1057 }
1058
1059 fn consummatedrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]consummated().(&mut self) -> bool {
1060 self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().consummatedrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consummated().()
1061 }
1062
1063 fn read_be_u16rust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]read_be_u16().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u16, 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#> {
1064 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().read_be_u16rust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_be_u16().();
1065 }
1066
1067 fn read_be_u32rust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]read_be_u32().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u32, 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#> {
1068 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().read_be_u32rust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_be_u32().();
1069 }
1070
1071 fn read_torust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]read_to().(&mut self, terminal: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], 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#>
1072 {
1073 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().read_torust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_to().(terminal);
1074 }
1075
1076 fn stealrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]steal().(&mut self, amount: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, 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#> {
1077 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().stealrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#steal().(amount);
1078 }
1079
1080 fn steal_eofrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]steal_eof().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, 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#> {
1081 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().steal_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#steal_eof().();
1082 }
1083
1084 fn drop_eofrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]drop_eof().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, 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#> {
1085 return self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().drop_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_eof().();
1086 }
1087
1088 fn get_mutrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`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>> {
1089 // Strip the outer box.
1090 self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().get_mutrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#get_mut().()
1091 }
1092
1093 fn get_refrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`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>> {
1094 // Strip the outer box.
1095 self.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsRef<T>`]as_ref().().get_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#get_ref().()
1096 }
1097
1098 fn into_boxedrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]into_boxed().<'b>(self) -> 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>
1099 where Selfrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]: 'b
1100 {
1101 self
1102 }
1103
1104 fn as_boxedrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]as_boxed().<'b>(self) -> 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>
1105 where Selfrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]: 'b
1106 {
1107 self
1108 }
1109
1110 fn into_innerrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`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 impl#[`Box<dyn BufferedReader<C> + 'a>`][`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>>
1111 where Selfrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]: 'b {
1112 // Strip the outer box.
1113 (*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().self).into_innerrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#into_inner().()
1114 }
1115
1116 fn cookie_setrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]cookie_set().(&mut self, cookie: C) -> C {
1117 self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().cookie_setrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_set().(cookie)
1118 }
1119
1120 fn cookie_refrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]cookie_ref().(&self) -> &C {
1121 self.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsRef<T>`]as_ref().().cookie_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_ref().()
1122 }
1123
1124 fn cookie_mutrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]cookie_mut().(&mut self) -> &mut C {
1125 self.as_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsMut<T>`]as_mut().().cookie_mutrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_mut().()
1126 }
1127 }
1128
1129 /// Make a `&mut T` where `T` implements `BufferedReader` look like a
1130 /// BufferedReader.
1131 impl <'a, T, C> BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> for &'a mut T
1132 where
1133 T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>,
1134 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# + 'a
1135 {
1136 fn bufferrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]buffer().(&self) -> &[u8] {
1137 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).bufferrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#buffer().()
1138 }
1139
1140 fn datarust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`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#> {
1141 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(amount)
1142 }
1143
1144 fn data_hardrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`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#> {
1145 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_hard().(amount)
1146 }
1147
1148 fn data_eofrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]data_eof().(&mut self) -> 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#> {
1149 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().()
1150 }
1151
1152 fn consumerust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]consume().(&mut self, amount: usize) -> &[u8] {
1153 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(amount)
1154 }
1155
1156 fn data_consumerust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]data_consume().(&mut self, amount: usize)
1157 -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], 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#> {
1158 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).data_consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume().(amount)
1159 }
1160
1161 fn data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`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#> {
1162 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(amount)
1163 }
1164
1165 fn consummatedrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]consummated().(&mut self) -> bool {
1166 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).consummatedrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consummated().()
1167 }
1168
1169 fn read_be_u16rust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]read_be_u16().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u16, 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#> {
1170 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).read_be_u16rust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_be_u16().()
1171 }
1172
1173 fn read_be_u32rust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]read_be_u32().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u32, 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#> {
1174 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).read_be_u32rust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_be_u32().()
1175 }
1176
1177 fn read_torust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]read_to().(&mut self, terminal: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[u8], 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#>
1178 {
1179 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).read_torust-analyzer cargo buffered-reader 1.4.1 BufferedReader#read_to().(terminal)
1180 }
1181
1182 fn stealrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]steal().(&mut self, amount: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, 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#> {
1183 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).stealrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#steal().(amount)
1184 }
1185
1186 fn steal_eofrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]steal_eof().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, 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#> {
1187 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).steal_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#steal_eof().()
1188 }
1189
1190 fn drop_eofrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]drop_eof().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, 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#> {
1191 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).drop_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_eof().()
1192 }
1193
1194 fn get_mutrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`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>> {
1195 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).get_mutrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#get_mut().()
1196 }
1197
1198 fn get_refrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`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>> {
1199 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).get_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#get_ref().()
1200 }
1201
1202 fn into_boxedrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]into_boxed().<'b>(self) -> 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>
1203 where Selfrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]: 'b
1204 {
1205 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().(self)
1206 }
1207
1208 fn as_boxedrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]as_boxed().<'b>(self) -> 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>
1209 where Selfrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]: 'b
1210 {
1211 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().(self)
1212 }
1213
1214 fn into_innerrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`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 impl#[`&'a mut T`][`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>>
1215 where Selfrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]: 'b
1216 {
1217 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1218 }
1219
1220 fn cookie_setrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]cookie_set().(&mut self, cookie: C) -> C {
1221 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).cookie_setrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_set().(cookie)
1222 }
1223
1224 fn cookie_refrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]cookie_ref().(&self) -> &C {
1225 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).cookie_refrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_ref().()
1226 }
1227
1228 fn cookie_mutrust-analyzer cargo buffered-reader 1.4.1 impl#[`&'a mut T`][`BufferedReader<C>`]cookie_mut().(&mut self) -> &mut C {
1229 (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self).cookie_mutrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#cookie_mut().()
1230 }
1231 }
1232
1233 // The file was created as follows:
1234 //
1235 // for i in $(seq 0 9999); do printf "%04d\n" $i; done > buffered-reader-test.txt
1236 #[cfg(test)]
1237 fn buffered_reader_test_data_checkrust-analyzer cargo buffered-reader 1.4.1 buffered_reader_test_data_check().<'a, T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> + '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#>(bio: &mut T) {
1238 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/;
1239
1240 for i in 0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range# rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#10000 {
1241 let consumed = {
1242 // Each number is 4 bytes plus a newline character.
1243 let d = bio.data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_hard().(5);
1244 if d.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() {
1245 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Error for i == {}: {:?}", i, d);
1246 }
1247 let d = d.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1248 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(d.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= 5);
1249 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:04}\n", i), strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&d[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
1250
1251 5
1252 };
1253
1254 bio.consumerust-analyzer cargo buffered-reader 1.4.1 BufferedReader#consume().(consumed);
1255 }
1256 }
1257
1258 #[cfg(test)]
1259 const BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA.: &[u8] =
1260 include_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_bytes!!("buffered-reader-test.txt");
1261
1262 #[cfg(test)]
1263 mod testrust-analyzer cargo buffered-reader 1.4.1 test/ {
1264 use superrust-analyzer cargo buffered-reader 1.4.1 crate/::*;
1265
1266 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1267 fn buffered_reader_eof_testrust-analyzer cargo buffered-reader 1.4.1 test/buffered_reader_eof_test().() {
1268 let data = BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA.;
1269 // Make sure data_eof works.
1270 {
1271 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().(data);
1272 let amount = {
1273 bio.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().().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().()
1274 };
1275 bio.consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]consume().(amount);
1276 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bio.datarust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]data().(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().(), 0);
1277 }
1278
1279 // Try it again with a limitor.
1280 {
1281 let bio = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]new().(data);
1282 let mut bio2 = Limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/Limitor#::newrust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, ()>`]new().(
1283 bio, (data.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][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2) as u64);
1284 let amount = {
1285 bio2.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().().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().()
1286 };
1287 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(amount, data.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][`Div<Self>`]div(). 2);
1288 bio2.consumerust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, C>`][`BufferedReader<C>`]consume().(amount);
1289 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(bio2.datarust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, C>`][`BufferedReader<C>`]data().(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().(), 0);
1290 }
1291 }
1292
1293 #[cfg(test)]
1294 fn buffered_reader_read_test_auxrust-analyzer cargo buffered-reader 1.4.1 test/buffered_reader_read_test_aux().<'a, T: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> + '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#>
1295 (mut bio: T, data: &[u8]) {
1296 let mut buffer = [0; 99];
1297
1298 // Make sure the test file has more than buffer.len() bytes
1299 // worth of data.
1300 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(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 cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
1301
1302 // The number of reads we'll have to perform.
1303 let iters = (data.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][`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().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().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
1304 // Iterate more than the number of required reads to check
1305 // what happens when we try to read beyond the end of the
1306 // file.
1307 for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#iters 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().2 {
1308 let data_start = (i 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 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().buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
1309
1310 // We don't want to just check that read works in
1311 // isolation. We want to be able to mix .read and .data
1312 // calls.
1313 {
1314 let result = bio.datarust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data().(buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
1315 let buffer = result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1316 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().buffer.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
1317 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(buffer,
1318 &data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().data_start..data_start +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 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/index/Index#index().);
1319 }
1320 }
1321
1322 // Now do the actual read.
1323 let result = bio.readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read().(&mut buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()...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 array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().);
1324 let got = result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1325 if got 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 {
1326 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0..got]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().,
1327 &data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().data_start..data_start +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). got]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
1328 }
1329
1330 if i 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().iters {
1331 // We should have read everything.
1332 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(got == 0);
1333 } else 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().iters {
1334 // The last read. This may be less than buffer.len().
1335 // But it should include at least one byte.
1336 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(0 <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). got);
1337 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(got <= buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
1338 } else {
1339 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(got, buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
1340 }
1341 }
1342 }
1343
1344 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1345 fn buffered_reader_read_testrust-analyzer cargo buffered-reader 1.4.1 test/buffered_reader_read_test().() {
1346 let data = BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA.;
1347 {
1348 let bio = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]new().(data);
1349 buffered_reader_read_test_auxrust-analyzer cargo buffered-reader 1.4.1 test/buffered_reader_read_test_aux(). (bio, data);
1350 }
1351
1352 {
1353 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#;
1354 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#;
1355
1356 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"),
1357 "src",
1358 "buffered-reader-test.txt"]
1359 .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().();
1360
1361 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().()));
1362 let 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#);
1363 buffered_reader_read_test_auxrust-analyzer cargo buffered-reader 1.4.1 test/buffered_reader_read_test_aux(). (bio, data);
1364 }
1365 }
1366
1367 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1368 fn drop_untilrust-analyzer cargo buffered-reader 1.4.1 test/drop_until().() {
1369 let data : &[u8] = &b"abcd"[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().;
1370 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().(data);
1371
1372 // Matches the 'a' at 0 and consumes 0 bytes.
1373 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(b"ab").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0);
1374 // Matches the 'b' at 1 and consumes 1 byte.
1375 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(b"bc").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 1);
1376 // Matches the 'b' at 1 and consumes 0 bytes.
1377 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(b"ab").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0);
1378 // Matches the 'd' at 4 and consumes 2 bytes.
1379 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(b"de").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 2);
1380 // Matches nothing, consuming the last 1 byte.
1381 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(b"e").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 1);
1382 // Matches nothing, consuming nothing.
1383 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_untilrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_until().(b"e").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 0);
1384 }
1385
1386 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1387 fn drop_throughrust-analyzer cargo buffered-reader 1.4.1 test/drop_through().() {
1388 let data : &[u8] = &b"abcd"[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().;
1389 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().(data);
1390
1391 // Matches the 'a' at 0 and consumes 1 byte.
1392 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_throughrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_through().(b"ab", false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1393 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b'a'), 1));
1394 // Matches the 'b' at 1 and consumes 1 byte.
1395 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_throughrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_through().(b"ab", false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1396 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b'b'), 1));
1397 // Matches the 'd' at 4 and consumes 2 byte.
1398 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(reader.drop_throughrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_through().(b"def", false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1399 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b'd'), 2));
1400 // Doesn't match (eof).
1401 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.drop_throughrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_through().(b"def", false).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1402 // Matches EOF.
1403 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reader.drop_throughrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#drop_through().(b"def", true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().0.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
1404 }
1405
1406 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1407 fn copyrust-analyzer cargo buffered-reader 1.4.1 test/copy().() -> 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#<()> {
1408 // The memory reader has all the data buffered, copying it
1409 // will issue a single write.
1410 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().(BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA.);
1411 let mut sink = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1412 let amount = bio.copyrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#copy().(&mut sink)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1413 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(amount, 50_000);
1414 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&sink[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA.);
1415
1416 // The generic reader uses buffers of the given chunk size,
1417 // copying it will issue multiple writes.
1418 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().(BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(64));
1419 let mut sink = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1420 let amount = bio.copyrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#copy().(&mut sink)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1421 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(amount, 50_000);
1422 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&sink[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., BUFFERED_READER_TEST_DATArust-analyzer cargo buffered-reader 1.4.1 BUFFERED_READER_TEST_DATA.);
1423 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1424 }
1425
1426 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1427 fn mutable_referencerust-analyzer cargo buffered-reader 1.4.1 test/mutable_reference().() {
1428 use craterust-analyzer cargo buffered-reader 1.4.1 crate/::Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#;
1429 const DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA. : &[u8] = b"01234567890123456789suffix";
1430
1431 /// API that consumes the memory reader.
1432 fn parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().<B: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<()>>(mut r: B) {
1433 let d = r.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1434 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(d.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= 10);
1435 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&d[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
1436 droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(r); // We consumed the reader.
1437 }
1438
1439 let mut mem = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]new().(DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA.);
1440 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut mem);
1441 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut mem);
1442 let suffix = mem.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1443 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, b"suffix");
1444
1445 let mut mem = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]new().(DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA.);
1446 let mut limitor = Limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/Limitor#::newrust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, ()>`]new().(&mut mem, 20);
1447 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1448 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1449 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(limitor.eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#eof().());
1450 let suffix = mem.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1451 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, b"suffix");
1452 }
1453
1454 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1455 fn mutable_reference_with_cookierust-analyzer cargo buffered-reader 1.4.1 test/mutable_reference_with_cookie().() {
1456 use craterust-analyzer cargo buffered-reader 1.4.1 crate/::Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#;
1457 const DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA. : &[u8] = b"01234567890123456789suffix";
1458
1459 /// API that consumes the memory reader.
1460 fn parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().<B, C>(mut r: B)
1461 where B: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>,
1462 C: 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/::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#
1463 {
1464 let d = r.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1465 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(d.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= 10);
1466 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&d[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
1467 droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(r); // We consumed the reader.
1468 }
1469
1470 #[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:)]
1471 struct Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie# {
1472 }
1473
1474 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie# {
1475 fn defaultrust-analyzer cargo buffered-reader 1.4.1 test/impl#[Cookie][Default]default().() -> Selfrust-analyzer cargo buffered-reader 1.4.1 test/impl#[Cookie][Default] { Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie# {} }
1476 }
1477
1478 let mut mem = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::with_cookierust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]with_cookie().(DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA., Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie#::defaultrust-analyzer cargo buffered-reader 1.4.1 test/impl#[Cookie][Default]default().());
1479 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut mem);
1480 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut mem);
1481 let suffix = mem.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1482 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, b"suffix");
1483
1484 let mut mem = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::with_cookierust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]with_cookie().(DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA., Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie#::defaultrust-analyzer cargo buffered-reader 1.4.1 test/impl#[Cookie][Default]default().());
1485 let mut limitor = Limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/Limitor#::with_cookierust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, C>`]with_cookie().(
1486 &mut mem, 20, Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie#::defaultrust-analyzer cargo buffered-reader 1.4.1 test/impl#[Cookie][Default]default().());
1487 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1488 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1489 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(limitor.eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#eof().());
1490 let suffix = mem.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1491 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, b"suffix");
1492
1493 let mut mem = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::with_cookierust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]with_cookie().(DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA., Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie#::defaultrust-analyzer cargo buffered-reader 1.4.1 test/impl#[Cookie][Default]default().());
1494 let mut mem = 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().(&mut mem) as Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie#>>;
1495 let mut limitor = Limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/Limitor#::with_cookierust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, C>`]with_cookie().(
1496 &mut mem, 20, Cookierust-analyzer cargo buffered-reader 1.4.1 test/Cookie#::defaultrust-analyzer cargo buffered-reader 1.4.1 test/impl#[Cookie][Default]default().());
1497 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1498 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1499 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(limitor.eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#eof().());
1500 let suffix = mem.data_eofrust-analyzer cargo buffered-reader 1.4.1 impl#[`Box<dyn BufferedReader<C> + 'a>`][`BufferedReader<C>`]data_eof().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1501 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, b"suffix");
1502 }
1503
1504 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1505 fn mutable_reference_innerrust-analyzer cargo buffered-reader 1.4.1 test/mutable_reference_inner().() {
1506 use craterust-analyzer cargo buffered-reader 1.4.1 crate/::Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#;
1507 const DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA. : &[u8] = b"01234567890123456789suffix";
1508
1509 /// API that consumes the memory reader.
1510 fn parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().<B: BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<()>>(mut r: B) {
1511 let d = r.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_consume_hard().(10).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1512 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(d.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >= 10);
1513 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&d[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
1514 droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(r); // We consumed the reader.
1515 }
1516
1517 let mut mem = Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#::newrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, ()>`]new().(DATArust-analyzer cargo buffered-reader 1.4.1 test/DATA.);
1518 let mut limitor = Limitorrust-analyzer cargo buffered-reader 1.4.1 limitor/Limitor#::newrust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, ()>`]new().(&mut mem, 20);
1519 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1520 parse_ten_bytesrust-analyzer cargo buffered-reader 1.4.1 test/parse_ten_bytes().(&mut limitor);
1521 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(limitor.eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#eof().());
1522
1523 // Check that get_mut returns `mem` by reading from the inner
1524 // and checking that we get more data.
1525 let mem = limitor.get_mutrust-analyzer cargo buffered-reader 1.4.1 limitor/impl#[`Limitor<T, C>`][`BufferedReader<C>`]get_mut().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("have inner");
1526 let suffix = mem.data_eofrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_eof().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1527 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suffix, b"suffix");
1528 }
1529 }