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>
impl<'a> StrTextReader<'a>
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.
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.
Trait Implementations§
Source§impl<'a> Debug for StrTextReader<'a>
impl<'a> Debug for StrTextReader<'a>
Source§impl TextLineReader for StrTextReader<'_>
impl TextLineReader for StrTextReader<'_>
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 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<'_>
impl TextReader for StrTextReader<'_>
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, 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>
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.