| 1 | //! A mmapping `BufferedReader` implementation for files. |
| 2 | //! |
| 3 | //! On my (Justus) system, this implementation improves the |
| 4 | //! performance of the statistics example by ~10% over the |
| 5 | //! Generic. |
| 6 | |
| 7 | use libcrust-analyzer cargo libc 0.2.186 crate/::{mmaprust-analyzer cargo libc 0.2.186 mmap()., munmaprust-analyzer cargo libc 0.2.186 munmap()., PROT_READrust-analyzer cargo libc 0.2.186 unix/linux_like/PROT_READ., MAP_PRIVATErust-analyzer cargo libc 0.2.186 unix/linux_like/MAP_PRIVATE.}; |
| 8 | 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/; |
| 9 | 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/; |
| 10 | 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/; |
| 11 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/io/::AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#; |
| 12 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/; |
| 13 | 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/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#}; |
| 14 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/; |
| 15 | |
| 16 | use superrust-analyzer cargo buffered-reader 1.4.1 crate/::*; |
| 17 | use craterust-analyzer cargo buffered-reader 1.4.1 crate/::file_errorrust-analyzer cargo buffered-reader 1.4.1 file_error/::FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#; |
| 18 | |
| 19 | // For small files, the overhead of manipulating the page table is not |
| 20 | // worth the gain. This threshold has been chosen so that on my |
| 21 | // (Justus) system, mmaping is faster than sequentially reading. |
| 22 | const MMAP_THRESHOLDrust-analyzer cargo buffered-reader 1.4.1 file_unix/MMAP_THRESHOLD.: u64 = 16 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().4096; |
| 23 | |
| 24 | /// Wraps files using `mmap`(). |
| 25 | /// |
| 26 | /// This implementation tries to mmap the file, falling back to |
| 27 | /// just using a generic reader. |
| 28 | pub struct Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'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#>(Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#<'a, C>, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#); |
| 29 | |
| 30 | assert_send_and_syncrust-analyzer cargo buffered-reader 1.4.1 macros/assert_send_and_sync!!(Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'_, C> |
| 31 | 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#); |
| 32 | |
| 33 | impl<'a, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'a, C> { |
| 34 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 35 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{} {:?}", self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0., self.1rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#1..displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl<'a, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'a, C> { |
| 40 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 41 | f.debug_tuplerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_tuple().("File") |
| 42 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(&self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0.) |
| 43 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(&self.1rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#1.) |
| 44 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]finish().() |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /// The implementation. |
| 49 | enum Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#<'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#> { |
| 50 | Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#<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#, C>), |
| 51 | Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { |
| 52 | readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader.: Memoryrust-analyzer cargo buffered-reader 1.4.1 memory/Memory#<'a, C>, |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | 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#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#<'a, C> { |
| 57 | fn droprust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`Imp<'a, C>`][Drop]drop().(&mut self) { |
| 58 | match self { |
| 59 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(_) => (), |
| 60 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., } => { |
| 61 | let buf = reader.source_bufferrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]source_buffer().(); |
| 62 | unsafe { |
| 63 | munmaprust-analyzer cargo libc 0.2.186 munmap().(buf.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as *mut _, buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 64 | } |
| 65 | }, |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | impl<'a, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#<'a, C> { |
| 71 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`Imp<'a, C>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 72 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "File(")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 73 | match self { |
| 74 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(_) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Generic")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 75 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { .. } => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Memory")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 76 | }; |
| 77 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ")") |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | impl<'a, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#<'a, C> { |
| 82 | fn fmtrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`Imp<'a, C>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 83 | match self { |
| 84 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref g) => |
| 85 | f.debug_tuplerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_tuple().("Generic") |
| 86 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(&g) |
| 87 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]finish().(), |
| 88 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., } => |
| 89 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("Mmap") |
| 90 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("addr", &reader.source_bufferrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]source_buffer().().as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().()) |
| 91 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("length", &reader.source_bufferrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`]source_buffer().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 92 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("reader", reader) |
| 93 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().(), |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | impl<'a> Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'a, ()> { |
| 99 | /// Wraps a [`fs::File`]. |
| 100 | /// |
| 101 | /// The given `path` should be the path that has been used to |
| 102 | /// obtain `file` from. It is used in error messages to provide |
| 103 | /// context to the user. |
| 104 | /// |
| 105 | /// While this is slightly less convenient than [`Self::open`], it |
| 106 | /// allows one to inspect or manipulate the [`fs::File`] object |
| 107 | /// before handing it off. For example, one can inspect the |
| 108 | /// metadata. |
| 109 | pub fn newrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, ()>`]new().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(file: 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#, path: P) -> 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#<Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, ()>`]> { |
| 110 | Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, ()>`]::new_with_cookierust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]new_with_cookie().(file, path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), ()) |
| 111 | } |
| 112 | |
| 113 | /// Opens the given file. |
| 114 | pub fn openrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, ()>`]open().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> 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#<Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, ()>`]> { |
| 115 | Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, ()>`]::with_cookierust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]with_cookie().(path, ()) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | 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#> Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'a, C> { |
| 120 | /// Like [`Self::new`], but sets a cookie. |
| 121 | /// |
| 122 | /// The given `path` should be the path that has been used to |
| 123 | /// obtain `file` from. It is used in error messages to provide |
| 124 | /// context to the user. |
| 125 | /// |
| 126 | /// While this is slightly less convenient than |
| 127 | /// [`Self::with_cookie`], it allows one to inspect or manipulate |
| 128 | /// the [`fs::File`] object before handing it off. For example, |
| 129 | /// one can inspect the metadata. |
| 130 | pub fn new_with_cookierust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]new_with_cookie().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(file: 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#, path: P, cookie: C) |
| 131 | -> 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#<Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]> { |
| 132 | let path = path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 133 | |
| 134 | // As fallback, we use a generic reader. |
| 135 | let generic = |file, cookie| { |
| 136 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#( |
| 137 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#( |
| 138 | Genericrust-analyzer cargo buffered-reader 1.4.1 generic/Generic#::with_cookierust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`]with_cookie().(file, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, cookie)), |
| 139 | path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 140 | }; |
| 141 | |
| 142 | // For testing and benchmarking purposes, we use the variable |
| 143 | // SEQUOIA_DONT_MMAP to turn off mmapping. |
| 144 | if ::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().("SEQUOIA_DONT_MMAP").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 145 | return generic(file, cookie); |
| 146 | } |
| 147 | |
| 148 | let length = |
| 149 | file.metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]metadata().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#::newrust-analyzer cargo buffered-reader 1.4.1 file_error/impl#[FileError]new().(path, e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]len().(); |
| 150 | |
| 151 | // For small files, the overhead of manipulating the page |
| 152 | // table is not worth the gain. |
| 153 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().MMAP_THRESHOLDrust-analyzer cargo buffered-reader 1.4.1 file_unix/MMAP_THRESHOLD. { |
| 154 | return generic(file, cookie); |
| 155 | } |
| 156 | |
| 157 | // Be nice to 32 bit systems. |
| 158 | let length: usize = match length.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() { |
| 159 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) => v, |
| 160 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => return generic(file, cookie), |
| 161 | }; |
| 162 | |
| 163 | let fd = file.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().(); |
| 164 | let addr = unsafe { |
| 165 | mmaprust-analyzer cargo libc 0.2.186 mmap().(ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(), length, PROT_READrust-analyzer cargo libc 0.2.186 unix/linux_like/PROT_READ., MAP_PRIVATErust-analyzer cargo libc 0.2.186 unix/linux_like/MAP_PRIVATE., |
| 166 | fd, 0) |
| 167 | }; |
| 168 | if addr rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`][`PartialEq<Self>`]eq().libcrust-analyzer cargo libc 0.2.186 crate/::MAP_FAILEDrust-analyzer cargo libc 0.2.186 unix/linux_like/MAP_FAILED. { |
| 169 | return generic(file, cookie); |
| 170 | } |
| 171 | |
| 172 | let slice = unsafe { |
| 173 | slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::from_raw_partsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/raw/from_raw_parts().(addr as *const u8, length) |
| 174 | }; |
| 175 | |
| 176 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#( |
| 177 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { |
| 178 | readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader.: 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().(slice, cookie), |
| 179 | }, |
| 180 | path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 181 | )) |
| 182 | } |
| 183 | |
| 184 | /// Like [`Self::open`], but sets a cookie. |
| 185 | pub fn with_cookierust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]with_cookie().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P, cookie: C) -> 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#<Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]> { |
| 186 | let path = path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 187 | let file = 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#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(path).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#::newrust-analyzer cargo buffered-reader 1.4.1 file_error/impl#[FileError]new().(path, e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 188 | Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]::new_with_cookierust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`]new_with_cookie().(file, path, cookie) |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | impl<'a, C: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'a, C> { |
| 193 | fn readrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][Read]read().(&mut self, buf: &mut [u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 194 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 195 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.readrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][Read]read().(buf), |
| 196 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.readrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][Read]read().(buf), |
| 197 | }.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#::newrust-analyzer cargo buffered-reader 1.4.1 file_error/impl#[FileError]new().(&self.1rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#1., e)) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | 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 Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#<'a, C> { |
| 202 | fn bufferrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]buffer().(&self) -> &[u8] { |
| 203 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 204 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref reader) => reader.bufferrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]buffer().(), |
| 205 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.bufferrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]buffer().(), |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | fn datarust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]data().(&mut self, amount: usize) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&[u8]> { |
| 210 | let path = &self.1rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#1.; |
| 211 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 212 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.datarust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data().(amount), |
| 213 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.datarust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]data().(amount), |
| 214 | }.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#::newrust-analyzer cargo buffered-reader 1.4.1 file_error/impl#[FileError]new().(path, e)) |
| 215 | } |
| 216 | |
| 217 | fn data_hardrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]data_hard().(&mut self, amount: usize) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&[u8]> { |
| 218 | let path = &self.1rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#1.; |
| 219 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 220 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.data_hardrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data_hard().(amount), |
| 221 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.data_hardrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#data_hard().(amount), |
| 222 | }.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#::newrust-analyzer cargo buffered-reader 1.4.1 file_error/impl#[FileError]new().(path, e)) |
| 223 | } |
| 224 | |
| 225 | fn consumerust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]consume().(&mut self, amount: usize) -> &[u8] { |
| 226 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 227 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.consumerust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]consume().(amount), |
| 228 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]consume().(amount), |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | fn data_consumerust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]data_consume().(&mut self, amount: usize) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&[u8]> { |
| 233 | let path = &self.1rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#1.; |
| 234 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 235 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.data_consumerust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data_consume().(amount), |
| 236 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.data_consumerust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]data_consume().(amount), |
| 237 | }.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#::newrust-analyzer cargo buffered-reader 1.4.1 file_error/impl#[FileError]new().(path, e)) |
| 238 | } |
| 239 | |
| 240 | fn data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]data_consume_hard().(&mut self, amount: usize) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&[u8]> { |
| 241 | let path = &self.1rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#1.; |
| 242 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 243 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]data_consume_hard().(amount), |
| 244 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.data_consume_hardrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]data_consume_hard().(amount), |
| 245 | }.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| FileErrorrust-analyzer cargo buffered-reader 1.4.1 file_error/FileError#::newrust-analyzer cargo buffered-reader 1.4.1 file_error/impl#[FileError]new().(path, e)) |
| 246 | } |
| 247 | |
| 248 | fn get_mutrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]get_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut dyn BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>> { |
| 249 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 250 | } |
| 251 | |
| 252 | fn get_refrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]get_ref().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&dyn BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C>> { |
| 253 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 254 | } |
| 255 | |
| 256 | fn into_innerrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]into_inner().<'b>(self: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn BufferedReaderrust-analyzer cargo buffered-reader 1.4.1 BufferedReader#<C> + 'b>> |
| 257 | where Selfrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]: 'b { |
| 258 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 259 | } |
| 260 | |
| 261 | fn cookie_setrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]cookie_set().(&mut self, cookie: C) -> C { |
| 262 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 263 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.cookie_setrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]cookie_set().(cookie), |
| 264 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.cookie_setrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]cookie_set().(cookie), |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | fn cookie_refrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]cookie_ref().(&self) -> &C { |
| 269 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 270 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref reader) => reader.cookie_refrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]cookie_ref().(), |
| 271 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.cookie_refrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]cookie_ref().(), |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | fn cookie_mutrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, C>`][`BufferedReader<C>`]cookie_mut().(&mut self) -> &mut C { |
| 276 | match self.0rust-analyzer cargo buffered-reader 1.4.1 file_unix/File#0. { |
| 277 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Genericrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Generic#(ref mut reader) => reader.cookie_mutrust-analyzer cargo buffered-reader 1.4.1 generic/impl#[`Generic<T, C>`][`BufferedReader<C>`]cookie_mut().(), |
| 278 | Imprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#::Mmaprust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap# { ref mut readerrust-analyzer cargo buffered-reader 1.4.1 file_unix/Imp#Mmap#reader., .. } => reader.cookie_mutrust-analyzer cargo buffered-reader 1.4.1 memory/impl#[`Memory<'a, C>`][`BufferedReader<C>`]cookie_mut().(), |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | #[cfg(test)] |
| 284 | mod testrust-analyzer cargo buffered-reader 1.4.1 file_unix/test/ { |
| 285 | use superrust-analyzer cargo buffered-reader 1.4.1 file_unix/::*; |
| 286 | |
| 287 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 288 | fn error_contains_pathrust-analyzer cargo buffered-reader 1.4.1 file_unix/test/error_contains_path().() { |
| 289 | let p = "/i/do/not/exist"; |
| 290 | let e = Filerust-analyzer cargo buffered-reader 1.4.1 file_unix/File#::openrust-analyzer cargo buffered-reader 1.4.1 file_unix/impl#[`File<'a, ()>`]open().(p).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(); |
| 291 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(p)); |
| 292 | } |
| 293 | } |