Skip to main content

StrTextReader

Struct StrTextReader 

Source
pub struct StrTextReader<'a> { /* private fields */ }
Expand description

Text reader over a borrowed string slice.

The reader borrows its input and tracks its physical UTF-8 byte offset, including any character read ahead while recognizing line endings. It recognizes LF, CRLF, and CR line endings by default.

§Type Parameters

  • 'a: Lifetime of the borrowed text.

§Examples

use qubit_io_text::StrTextReader;
use qubit_io_text::TextReader;

let mut reader = StrTextReader::new("hello");
let mut output = String::new();
let count = reader.read_to_string(&mut output)?;
assert_eq!(count, 5);
assert_eq!(output, "hello");

Implementations§

Source§

impl<'a> StrTextReader<'a>

Source

pub const fn new(text: &'a str) -> Self

Creates a reader over text.

§Parameters
  • text: Borrowed text to read.
§Returns

A reader positioned at the start of the text.

Source

pub const fn position(&self) -> usize

Returns the physical UTF-8 byte position in the underlying string.

Line-ending detection may read one character ahead and retain it for the next read. This position includes that character and can equal the input length before all characters have been returned. Reading a retained character does not advance this position. Do not use this value as a checkpoint of text already delivered to the caller.

§Returns

The underlying byte offset, including any line-ending lookahead.

Source

pub const fn line_endings(&self) -> LineEndingSet

Returns the line endings recognized by this reader.

Source

pub const fn with_line_endings(self, line_endings: LineEndingSet) -> Self

Sets the line endings recognized by TextLineReader::read_line.

§Parameters
  • line_endings: Accepted line-ending sequences.
§Returns

This reader with the requested line-ending configuration.

Trait Implementations§

Source§

impl<'a> Debug for StrTextReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TextLineReader for StrTextReader<'_>

Source§

fn read_line(&mut self, output: &mut String) -> Result<bool, Self::Error>

Appends the next line according to this reader’s configured line endings, returning whether a line was read. A trailing terminator does not produce an additional empty line.

§Parameters
  • output: String that receives the line contents, without its terminator.
§Returns

true if a line was read, or false if no text remains. The result is always successful.

Source§

impl TextReader for StrTextReader<'_>

Source§

type Error = !

This reader cannot fail because it reads from an in-memory string slice.

Source§

fn read_char(&mut self) -> Result<Option<char>, Self::Error>

Returns the next Unicode scalar value, first consuming any character retained by line-ending lookahead.

§Returns

Ok(Some(ch)) when a character was read, or Ok(None) when the input is exhausted.

Source§

fn read_chars( &mut self, output: &mut Vec<char>, max: usize, ) -> Result<usize, Self::Error>

Appends up to max characters, including a retained lookahead character when the limit is nonzero, and returns the number appended.

§Parameters
  • output: Buffer that receives the characters.
  • max: Maximum number of characters to append.
§Returns

The number of characters appended. The result is always successful.

Source§

fn read_to_string(&mut self, output: &mut String) -> Result<usize, Self::Error>

Appends all remaining text and any retained lookahead character, then returns the number of characters appended.

§Parameters
  • output: String that receives the remaining text.
§Returns

The number of characters appended. The result is always successful.

Auto Trait Implementations§

§

impl<'a> Forget for StrTextReader<'a>

§

impl<'a> Freeze for StrTextReader<'a>

§

impl<'a> Move for StrTextReader<'a>

§

impl<'a> RefUnwindSafe for StrTextReader<'a>

§

impl<'a> Send for StrTextReader<'a>

§

impl<'a> Sync for StrTextReader<'a>

§

impl<'a> Unpin for StrTextReader<'a>

§

impl<'a> UnsafeUnpin for StrTextReader<'a>

§

impl<'a> UnwindSafe for StrTextReader<'a>

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.