Skip to main content

ForwardText

Struct ForwardText 

Source
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

Source

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.

Source

pub fn from_owned(text: String) -> Self

Text the caller already holds. Page release is a no-op.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Source

pub fn as_str(&self) -> Result<&str, Utf8Error>

The file as text when every byte is UTF-8.

Source

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.

Auto Trait Implementations§

§

impl Forget for ForwardText

§

impl Freeze for ForwardText

§

impl Move for ForwardText

§

impl RefUnwindSafe for ForwardText

§

impl Send for ForwardText
where RawVecInner: Send, MmapInner: Send,

§

impl Sync for ForwardText
where RawVecInner: Sync, MmapInner: Sync,

§

impl Unpin for ForwardText
where *const u8 is !null: Unpin, *mut c_void: Unpin,

§

impl UnsafeUnpin for ForwardText

§

impl UnwindSafe for ForwardText
where RawVecInner: UnwindSafe, *mut c_void: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.