pub struct StringTextReader { /* private fields */ }Expand description
Text reader over an owned string.
The reader 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.
§Examples
use qubit_io_text::StringTextReader;
use qubit_io_text::TextReader;
let mut reader = StringTextReader::new(String::from("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 StringTextReader
impl StringTextReader
Sourcepub const fn position(&self) -> usize
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.
Sourcepub const fn line_endings(&self) -> LineEndingSet
pub const fn line_endings(&self) -> LineEndingSet
Returns the line endings recognized by this reader.
§Returns
The line endings recognized by this reader.
Sourcepub const fn with_line_endings(self, line_endings: LineEndingSet) -> Self
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.
Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Trait Implementations§
Source§impl Debug for StringTextReader
impl Debug for StringTextReader
Source§impl TextLineReader for StringTextReader
impl TextLineReader for StringTextReader
Source§fn read_line(&mut self, output: &mut String) -> Result<bool, Self::Error>
fn read_line(&mut self, output: &mut String) -> Result<bool, Self::Error>
Appends the next line to output, consuming its recognized line ending
when present. Returns false only when no line content or terminator
remains; a final unterminated line is returned with true.
§Parameters
output: Destination that receives the next line, appended after its existing contents.
§Returns
Ok(true) when a line or final unterminated line is read, or
Ok(false) when no content or terminator remains.
§Errors
This in-memory reader never returns an error because its error type is
Infallible.
Source§impl TextReader for StringTextReader
impl TextReader for StringTextReader
Source§fn read_char(&mut self) -> Result<Option<char>, Self::Error>
fn read_char(&mut self) -> Result<Option<char>, Self::Error>
Returns the next Unicode scalar value, including any character retained
during line-ending lookahead, or None when the input is exhausted.
§Returns
Ok(Some(ch)) when a character is available, or Ok(None) at EOF.
§Errors
This in-memory reader never returns an error because its error type is
Infallible.
Source§fn read_chars(
&mut self,
output: &mut Vec<char>,
max: usize,
) -> Result<usize, Self::Error>
fn read_chars( &mut self, output: &mut Vec<char>, max: usize, ) -> Result<usize, Self::Error>
Appends up to max Unicode scalar values to output and returns the
number appended. A character retained during line-ending lookahead is
returned first; a zero limit leaves it pending.
§Parameters
output: Destination that receives the characters, appended after its existing contents.max: Maximum number of Unicode scalar values to append.
§Returns
Ok(count) with the number of characters appended.
§Errors
This in-memory reader never returns an error because its error type is
Infallible.
Source§fn read_to_string(&mut self, output: &mut String) -> Result<usize, Self::Error>
fn read_to_string(&mut self, output: &mut String) -> Result<usize, Self::Error>
Appends all remaining text, including any retained lookahead character,
to output and returns the number of Unicode scalar values appended.
§Parameters
output: Destination that receives the remaining text, appended after its existing contents.
§Returns
Ok(count) with the number of Unicode scalar values appended.
§Errors
This in-memory reader never returns an error because its error type is
Infallible.