pub struct ForwardText { /* private fields */ }Expand description
The text of one file, read from the front.
With map, an uncompressed file of 64 KiB or more stays mapped, and
Self::release_before advises MADV_DONTNEED for the pages before the
read position. On Linux that drops the file pages, so resident memory
stays near [RELEASE_STEP] instead of the file size. macOS gets the same
call, but its MADV_DONTNEED does not discard pages. Outside Unix the
release is a no-op. On those systems the whole file can become resident.
A mapped file is not a snapshot and must not change while it is read; a
truncation can end the process with SIGBUS.
Implementations§
Source§impl ForwardText
impl ForwardText
Sourcepub fn open(path: &Path, map: bool) -> Result<Self, Box<dyn Error>>
pub fn open(path: &Path, map: bool) -> Result<Self, Box<dyn Error>>
The bytes of path.
With map, a large plain file stays mapped. Without it, the bytes
are copied. A bad UTF-8 byte is left for the parser, which names
the line (CON-file.1, CON-num.10). Opening the file does not reject it.
Sourcepub fn from_owned(text: String) -> Self
pub fn from_owned(text: String) -> Self
Text the caller already holds. Page release is a no-op.
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn release_before(&mut self, pos: usize) -> Result<()>
pub fn release_before(&mut self, pos: usize) -> Result<()>
Release the mapped pages before byte pos once [RELEASE_STEP]
bytes have been read since the last release. A later read of them
maps them in again. A pos past the end counts as the end.